7 #include <rpmio_internal.h>
10 #include "stringbuf.h"
15 /*@access StringBuf @*/
17 char * rpmPermsString(int mode)
19 char *perms = xstrdup("----------");
23 else if (S_ISLNK(mode))
25 else if (S_ISFIFO(mode))
27 else if (S_ISSOCK(mode))
29 else if (S_ISCHR(mode))
31 else if (S_ISBLK(mode))
35 if (mode & S_IRUSR) perms[1] = 'r';
36 if (mode & S_IWUSR) perms[2] = 'w';
37 if (mode & S_IXUSR) perms[3] = 'x';
39 if (mode & S_IRGRP) perms[4] = 'r';
40 if (mode & S_IWGRP) perms[5] = 'w';
41 if (mode & S_IXGRP) perms[6] = 'x';
43 if (mode & S_IROTH) perms[7] = 'r';
44 if (mode & S_IWOTH) perms[8] = 'w';
45 if (mode & S_IXOTH) perms[9] = 'x';
48 perms[3] = ((mode & S_IXUSR) ? 's' : 'S');
51 perms[6] = ((mode & S_IXGRP) ? 's' : 'S');
54 perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
60 /**@todo Infinite loops through manifest files exist, operator error for now. */
61 int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
63 StringBuf sb = newStringBuf();
67 const char ** av = NULL;
68 int argc = (argcPtr ? *argcPtr : 0);
69 const char ** argv = (argvPtr ? *argvPtr : NULL);
70 /*@-type@*/ /* FIX: cast? */
71 FILE * f = fdGetFp(fd);
81 s = fgets(line, sizeof(line) - 1, f);
83 /* XXX Ferror check needed */
88 if ((se = strchr(s, '#')) != NULL) *se = '\0';
90 /* Trim white space. */
92 while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
94 while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
96 if (*s == '\0') continue;
98 /* Insure that file contains only ASCII */
104 /* Concatenate next line in buffer. */
107 appendStringBuf(sb, s);
111 if (s == NULL) /* XXX always true */
112 s = getStringBuf(sb);
120 /* Glob manifest items. */
121 rc = rpmGlob(s, &ac, &av);
124 /* Find 1st existing unprocessed arg. */
125 for (i = 0; i < argc; i++)
126 if (argv && argv[i]) break;
128 /* Concatenate existing unprocessed args after manifest contents. */
129 if (argv && i < argc) {
130 int nac = ac + (argc - i);
131 const char ** nav = xcalloc((nac + 1), sizeof(*nav));
134 memcpy(nav, av, ac * sizeof(*nav));
136 memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
140 *argvPtr = argv = _free(argv);
146 /* Save new argc/argv list. */
148 *argvPtr = _free(*argvPtr);
156 if (argvPtr == NULL || (rc != 0 && av)) {
158 for (i = 0; i < ac; i++)
159 /*@-unqualifiedtrans@*/av[i] = _free(av[i]); /*@=unqualifiedtrans@*/
160 /*@-dependenttrans@*/ av = _free(av); /*@=dependenttrans@*/
163 sb = freeStringBuf(sb);