"Fossies" - the Fresh Open Source Software Archive

Member "unipkg-0.6.5/common.h" (16 Dec 2005, 3359 Bytes) of package /linux/privat/old/unipkg-0.6.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /******************************************************************************\
    2 *                                                                              *
    3 * UniPKG (c) iSteve <isteve@bofh.cz>, 2005                                     *
    4 *                                                                              *
    5 * Universal PacKaGer.                                                          *
    6 * Licensed under GNU/GPL - if you don't like the software, fix it!             *
    7 *                                                                              *
    8 \******************************************************************************/
    9 
   10 #define A_COUNT     6
   11 
   12 #define A_IRRELEVANT    0
   13 #define A_INSTALL   1
   14 #define A_UPGRADE   2
   15 #define A_DOWNGRADE 3
   16 #define A_REINSTALL 4
   17 #define A_REMOVE    5
   18 
   19 
   20 #define F_IRRELEVANT    'X'
   21 #define F_REGULAR   'R'
   22 #define F_DIRECTORY 'D'
   23 
   24 typedef struct {
   25     off_t       len;
   26     char    *data;
   27     char    *parameters[A_COUNT];
   28 } lstring;
   29 
   30 typedef struct {
   31     char    flag;
   32     char    *name;
   33 } fileinfo;
   34 
   35 // The description of package which is common to most package formats
   36 typedef struct {
   37     char    *name;
   38     char    *version;
   39     char    *description;
   40     fileinfo    *files;
   41     
   42     lstring     preinst;
   43     lstring     postinst;
   44     lstring     prerm;
   45     lstring     postrm;
   46     
   47     unsigned long   filecount;
   48     unsigned long   pkgsize;
   49 } pkginfo;
   50 
   51 // Simple list of actions, ID and the text
   52 typedef struct{
   53     char    *text;
   54     int                 reval;
   55 } actions;
   56 
   57 // Definition of package, file pointer, filename, destination directory and action performed.
   58 typedef struct{
   59     FILE                *filepointer;
   60     pkginfo         *pinfo;
   61     char                *filename;
   62     char                *destdir;
   63     int             action;
   64 } packdef;
   65 
   66 // Pointers to database backend calls
   67 typedef struct {
   68     void        *libhandle;
   69     void        *(*opendb)(char*);
   70     int         (*writepkg)(void*, pkginfo*);
   71     int         (*readpkg)(void*, pkginfo*);
   72     int         (*delpkg)(void*, char*);
   73     int         (*findpkg)(void*, pkginfo, pkginfo*, int);
   74     void        (*rewinddb)(void*);
   75     void        (*closedb)(void*);
   76     int         (*iswriteable)(void*);
   77     int         (*syncdb)(void*);
   78 } databasecalls;
   79 
   80 // Pointers to package handling calls
   81 typedef struct {
   82     void        *libhandle;
   83     int         (*pkgdetails)(packdef, pkginfo*);
   84     int         (*pkginstall)(packdef);
   85     int         (*identify)(packdef);
   86     void            (*pkgscriptparams)(packdef, pkginfo*);
   87 } packagecalls;
   88 
   89 // Match flags
   90 #define MATCH_FILE      1
   91 #define MATCH_NAME      2
   92 #define MATCH_OVRWR     4
   93 
   94 
   95 // Suplementary functions
   96 #define FCHOWNMOD(fd, mode, uid, gid)   fchown(fd, uid, gid); fchmod(fd, mode);
   97 #define CHOWNMOD(fn, mode, uid, gid)    chown(fn, uid, gid); chmod(fn, mode);
   98 
   99 #ifndef WEXITSTATUS
  100  #define WEXITSTATUS(x) x
  101 #endif
  102 
  103 #ifndef __GNU_LIBRARY__
  104 static size_t strnlen(const char *s, size_t maxlen) {
  105     unsigned long len;
  106     
  107     while ((s[len] != '\0') && (len < maxlen)) {
  108         len++;
  109     }
  110     return len;
  111 }
  112 
  113 static char *strndup(const char *s, unsigned long n) {
  114     char                *tar;   
  115     unsigned long   cntr = 0;
  116     
  117     while ((s[cntr] != '\0') && (cntr < n)) {
  118         cntr++;
  119     }
  120     tar = malloc(cntr + 1);
  121     memcpy(tar, s, cntr);
  122     tar[cntr] = 0x0;
  123     
  124     return tar;
  125 }
  126 #endif
  127 
  128 // Function definitions
  129 void freepinfo(pkginfo *pinfo);
  130 void clearpinfo(pkginfo *pinfo);
  131 char *absolutizestr(char *toabs, char *dirprefix);
  132 int versioncmp(const char *val, const char *ref);
  133 char *needlelize(char *input);
  134 void addfile(pkginfo *pinfo, char *filename, char flag);
  135 int fisdir(char *filename);
  136 char *pstrnstr(char *haystack, char *needle, off_t len, off_t needlen);