diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2017-01-20 17:02:39 +0000 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2017-01-24 16:41:17 +0000 |
commit | c7d005ac1c92a6fee43554fffd9a6f38c0a6b962 (patch) | |
tree | 8297a1939ee63d2b1fd9862bb68dd5dde025a1f7 /base/gp_unifs.c | |
parent | 9568153b12b80d477f3031b88631910082a55bc8 (diff) | |
download | ghostpdl-c7d005ac1c92a6fee43554fffd9a6f38c0a6b962.tar.gz |
Add GS_NO_FILESYSTEM define for systems with no FS.
Some systems (such as ThreadX), have std headers that
define FILE, but do not actually have a real filing
system implementation. As such, they don't support
filing system enumeration.
We therefore introduce a GS_NO_FILESYSTEM define that
stubs out the code in these entrypoints.
At some point we may split the contents out to a different
platform, but this will probably require some careful
thinking about other functions in these files to avoid
duplication of code.
Diffstat (limited to 'base/gp_unifs.c')
-rw-r--r-- | base/gp_unifs.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/base/gp_unifs.c b/base/gp_unifs.c index 72bf7f24b..531f668eb 100644 --- a/base/gp_unifs.c +++ b/base/gp_unifs.c @@ -77,6 +77,9 @@ gp_open_scratch_file_generic(const gs_memory_t *mem, const char *mode, bool b64) { /* The -8 is for XXXXXX plus a possible final / and -. */ +#ifdef GS_NO_FILESYSTEM + return NULL; +#else int prefix_length = strlen(prefix); int len = gp_file_name_sizeof - prefix_length - 8; FILE *fp; @@ -134,6 +137,7 @@ gp_open_scratch_file_generic(const gs_memory_t *mem, if (fp == NULL) emprintf1(mem, "**** Could not open temporary file %s\n", fname); return fp; +#endif } FILE * gp_open_scratch_file(const gs_memory_t *mem, @@ -181,6 +185,9 @@ FILE *gp_open_scratch_file_rm(const gs_memory_t *mem, FILE *gp_fdup(FILE *f, const char *mode) { +#ifdef GS_NO_FILESYSTEM + return NULL; +#else int fd = fileno(f); if (fd < 0) return NULL; @@ -188,11 +195,14 @@ FILE *gp_fdup(FILE *f, const char *mode) if (fd < 0) return NULL; return fdopen(fd, mode); +#endif } int gp_fpread(char *buf, uint count, int64_t offset, FILE *f) { -#if defined(HAVE_PREAD_PWRITE) && HAVE_PREAD_PWRITE == 1 +#ifdef GS_NO_FILESYSTEM + return 0; +#elif defined(HAVE_PREAD_PWRITE) && HAVE_PREAD_PWRITE == 1 return pread(fileno(f), buf, count, offset); #else int c; @@ -214,7 +224,9 @@ int gp_fpread(char *buf, uint count, int64_t offset, FILE *f) int gp_fpwrite(char *buf, uint count, int64_t offset, FILE *f) { -#if defined(HAVE_PREAD_PWRITE) && HAVE_PREAD_PWRITE == 1 +#ifdef GS_NO_FILESYSTEM + return 0; +#elif defined(HAVE_PREAD_PWRITE) && HAVE_PREAD_PWRITE == 1 return pwrite(fileno(f), buf, count, offset); #else int c; @@ -247,6 +259,13 @@ gp_setmode_binary(FILE * pfile, bool mode) /* the original version of the following code, and Richard Mlynarik */ /* (mly@adoc.xerox.com) for an improved version. */ +#ifdef GS_NO_FILESYSTEM +struct file_enum_s { + int dummy; +}; + +static file_enum dummy_enum; +#else typedef struct dirstack_s dirstack; struct dirstack_s { dirstack *next; @@ -323,11 +342,15 @@ popdir(file_enum * pfen) gs_free_object(pfen->memory, d, "gp_enumerate_files(popdir)"); return true; } +#endif /* Initialize an enumeration. */ file_enum * gp_enumerate_files_init(const char *pat, uint patlen, gs_memory_t * mem) { +#ifdef GS_NO_FILESYSTEM + return &dummy_enum; +#else file_enum *pfen; char *p; char *work; @@ -406,12 +429,16 @@ gp_enumerate_files_init(const char *pat, uint patlen, gs_memory_t * mem) } return pfen; +#endif } /* Enumerate the next file. */ uint gp_enumerate_files_next(file_enum * pfen, char *ptr, uint maxlen) { +#ifdef GS_NO_FILESYSTEM + return ~(uint)0; +#else const dir_entry *de; char *work = pfen->work; int worklen = pfen->worklen; @@ -563,12 +590,16 @@ gp_enumerate_files_next(file_enum * pfen, char *ptr, uint maxlen) memcpy(ptr, work, len > maxlen ? maxlen : len); return len; +#endif } /* Clean up the file enumeration. */ void gp_enumerate_files_close(file_enum * pfen) { +#ifdef GS_NO_FILESYSTEM + /* No cleanup necessary */ +#else gs_memory_t *mem = pfen->memory; if_debug0m('e', mem, "[e]file_enum:Cleanup\n"); @@ -579,6 +610,7 @@ gp_enumerate_files_close(file_enum * pfen) gs_free_object(mem, (byte *) pfen->pattern, "gp_enumerate_files_close(pattern)"); gs_free_object(mem, pfen, "gp_enumerate_files_close"); +#endif } /* Test-cases: |