diff options
author | Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> | 2017-01-12 20:55:11 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2017-02-09 16:00:49 +0000 |
commit | aa2818628843205283c563865cd56b4091f2e37f (patch) | |
tree | 56c67d1367571ae62a3cc691e8cc8ecf378bcdb4 /base/mkromfs.c | |
parent | 98696f718b5c0f9a5fd9c33d61f81da469b9a4e1 (diff) | |
download | ghostpdl-aa2818628843205283c563865cd56b4091f2e37f.tar.gz |
Bug 697484: mkromfs: sort gp_enumerate_files output....
for deterministic ROM contents
gp_enumerate_files_next returns dir entries in the same order as returned
by readdir. Sort by name to generate deterministic output.
Diffstat (limited to 'base/mkromfs.c')
-rw-r--r-- | base/mkromfs.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/base/mkromfs.c b/base/mkromfs.c index 9b81c4636..b7799ae86 100644 --- a/base/mkromfs.c +++ b/base/mkromfs.c @@ -344,6 +344,7 @@ const gs_malloc_memory_t minimal_memory = { 0 /* max used */ }; +int cmpstringp(const void *p1, const void *p2); void put_uint32(FILE *out, const unsigned int q); void put_bytes_padded(FILE *out, unsigned char *p, unsigned int len); void inode_clear(romfs_inode* node); @@ -1542,6 +1543,15 @@ static unsigned long pscompact_getcompactedblock(pscompstate *psc, unsigned char return out-ubuf; } +int cmpstringp(const void *p1, const void *p2) +{ + /* The actual arguments to this function are "pointers to + pointers to char", but strcmp(3) arguments are "pointers + to char", hence the following cast plus dereference */ + + return strcmp(* (char * const *) p1, * (char * const *) p2); +} + /* This relies on the gp_enumerate_* which should not return directories, nor */ /* should it recurse into directories (unlike Adobe's implementation) */ /* paths are checked to see if they are an ordinary file or a path */ @@ -1561,6 +1571,8 @@ void process_path(char *path, const char *os_prefix, const char *rom_prefix, FILE *in; unsigned long psc_len; pscompstate psc = { 0 }; + unsigned long numfiles = 0; + char **foundfiles = NULL; prefixed_path = malloc(PATH_STR_LEN); found_path = malloc(PATH_STR_LEN); @@ -1598,6 +1610,17 @@ void process_path(char *path, const char *os_prefix, const char *rom_prefix, if (excluded) continue; + numfiles++; + foundfiles = realloc(foundfiles, sizeof(char *) * numfiles); + foundfiles[numfiles - 1] = strdup(found_path); + } + + qsort(foundfiles, numfiles, sizeof(char *), cmpstringp); + + while (numfiles--) { + found_path = *foundfiles; + foundfiles++; + /* process a file */ node = calloc(1, sizeof(romfs_inode)); /* get info for this file */ |