Add headerGet() flag to request argv-style NULL-terminated string arrays
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 20 Jan 2009 12:15:24 +0000 (14:15 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 20 Jan 2009 12:15:24 +0000 (14:15 +0200)
- easy to do and some places would like the data this way so why not...
- also add corresponding rpmtd flag so caller can verify he got what
  was requested

lib/header.c
lib/header.h
lib/rpmtd.h

index 0b6ed3e..96a6f1c 100644 (file)
@@ -1144,8 +1144,10 @@ static int copyTdEntry(const indexEntry entry, rpmtd td, headerGetFlags flags)
     /* ALLOC overrides MINMEM */
     int allocMem = flags & HEADERGET_ALLOC;
     int minMem = allocMem ? 0 : flags & HEADERGET_MINMEM;
+    int argvArray = (flags & HEADERGET_ARGV) ? 1 : 0;
 
     assert(td != NULL);
+    td->flags = RPMTD_IMMUTABLE;
     switch (entry->info.type) {
     case RPM_BIN_TYPE:
        /*
@@ -1198,7 +1200,7 @@ static int copyTdEntry(const indexEntry entry, rpmtd td, headerGetFlags flags)
     case RPM_STRING_ARRAY_TYPE:
     case RPM_I18NSTRING_TYPE:
     {  const char ** ptrEntry;
-       int tableSize = count * sizeof(char *);
+       int tableSize = (count + argvArray) * sizeof(char *);
        char * t;
        int i;
 
@@ -1218,6 +1220,10 @@ static int copyTdEntry(const indexEntry entry, rpmtd td, headerGetFlags flags)
            t = strchr(t, 0);
            t++;
        }
+       if (argvArray) {
+           *ptrEntry = NULL;
+           td->flags |= RPMTD_ARGV;
+       }
     }  break;
     case RPM_CHAR_TYPE:
     case RPM_INT8_TYPE:
@@ -1240,7 +1246,6 @@ static int copyTdEntry(const indexEntry entry, rpmtd td, headerGetFlags flags)
     td->type = entry->info.type;
     td->count = count;
 
-    td->flags = RPMTD_IMMUTABLE;
     if (td->data && entry->data != td->data) {
        td->flags |= RPMTD_ALLOCED;
     }
index 4f06c8f..afd25a9 100644 (file)
@@ -160,6 +160,7 @@ typedef enum headerGetFlags_e {
     HEADERGET_EXT      = (1 << 1), /* lookup extension types too */
     HEADERGET_RAW      = (1 << 2), /* return raw contents (no i18n lookups) */
     HEADERGET_ALLOC    = (1 << 3), /* always allocate memory for all data */
+    HEADERGET_ARGV     = (1 << 4), /* return string arrays NULL-terminated */
 } headerGetFlags;
 
 /** \ingroup header
index 8b43663..1bc515c 100644 (file)
@@ -13,6 +13,7 @@ typedef enum rpmtdFlags_e {
     RPMTD_ALLOCED      = (1 << 0),     /* was memory allocated? */
     RPMTD_PTR_ALLOCED  = (1 << 1),     /* were array pointers allocated? */
     RPMTD_IMMUTABLE    = (1 << 2),     /* header data or modifiable? */
+    RPMTD_ARGV         = (1 << 3),     /* string array is NULL-terminated? */
 } rpmtdFlags;
 
 /** \ingroup rpmtd