diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2014-11-03 14:40:38 -0500 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2014-11-03 14:40:38 -0500 |
commit | 6a9d48365f5044b64a6c270760808d17d475ca4b (patch) | |
tree | d612b2410fe9af333a79e524f5e5102f9754feed /io.c | |
parent | b4d06df669e1eaf6c98cacb5c5f299bb5324e804 (diff) | |
parent | 204bec7af64c61489e37007d45de936482007977 (diff) | |
download | egawk-6a9d48365f5044b64a6c270760808d17d475ca4b.tar.gz egawk-6a9d48365f5044b64a6c270760808d17d475ca4b.tar.bz2 egawk-6a9d48365f5044b64a6c270760808d17d475ca4b.zip |
Merge remote-tracking branch 'origin/master' into select
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 62 |
1 files changed, 16 insertions, 46 deletions
@@ -1559,6 +1559,17 @@ nextrres: * change the string. */ +/* + * 9/2014: Flow here is a little messy. + * + * For do_posix, we don't allow any of the special filenames. + * + * For do_traditional, we allow /dev/{stdin,stdout,stderr} since BWK awk + * (and mawk) support them. But we don't allow /dev/fd/N or /inet. + * + * Note that for POSIX systems os_devopen() is a no-op. + */ + int devopen(const char *name, const char *mode) { @@ -1574,7 +1585,7 @@ devopen(const char *name, const char *mode) flag = str2mode(mode); openfd = INVALID_HANDLE; - if (do_traditional) + if (do_posix) goto strictopen; if ((openfd = os_devopen(name, flag)) != INVALID_HANDLE) { @@ -1591,6 +1602,8 @@ devopen(const char *name, const char *mode) openfd = fileno(stdout); else if (strcmp(cp, "stderr") == 0 && (flag & O_ACCMODE) == O_WRONLY) openfd = fileno(stderr); + else if (do_traditional) + goto strictopen; else if (strncmp(cp, "fd/", 3) == 0) { struct stat sbuf; @@ -1603,6 +1616,8 @@ devopen(const char *name, const char *mode) /* do not set close-on-exec for inherited fd's */ if (openfd != INVALID_HANDLE) return openfd; + } else if (do_traditional) { + goto strictopen; } else if (inetfile(name, & isi)) { #ifdef HAVE_SOCKETS cp = (char *) name; @@ -2537,7 +2552,6 @@ do_getline(int into_variable, IOBUF *iop) typedef struct { const char *envname; char **dfltp; /* pointer to address of default path */ - char try_cwd; /* always search current directory? */ char **awkpath; /* array containing library search paths */ int max_pathlen; /* length of the longest item in awkpath */ } path_info; @@ -2545,13 +2559,11 @@ typedef struct { static path_info pi_awkpath = { /* envname */ "AWKPATH", /* dfltp */ & defpath, - /* try_cwd */ true, }; static path_info pi_awklibpath = { /* envname */ "AWKLIBPATH", /* dfltp */ & deflibpath, - /* try_cwd */ false, }; /* init_awkpath --- split path(=$AWKPATH) into components */ @@ -2609,30 +2621,6 @@ init_awkpath(path_info *pi) #undef INC_PATH } -/* get_cwd -- get current working directory */ - -static char * -get_cwd () -{ -#define BSIZE 100 - char *buf; - size_t bsize = BSIZE; - - emalloc(buf, char *, bsize * sizeof(char), "get_cwd"); - while (true) { - if (getcwd(buf, bsize) == buf) - return buf; - if (errno != ERANGE) { - efree(buf); - return NULL; - } - bsize *= 2; - erealloc(buf, char *, bsize * sizeof(char), "get_cwd"); - } -#undef BSIZE -} - - /* do_find_source --- search $AWKPATH for file, return NULL if not found */ static char * @@ -2654,24 +2642,6 @@ do_find_source(const char *src, struct stat *stb, int *errcode, path_info *pi) return NULL; } - /* try current directory before $AWKPATH search */ - if (pi->try_cwd && stat(src, stb) == 0) { - path = get_cwd(); - if (path == NULL) { - *errcode = errno; - return NULL; - } - erealloc(path, char *, strlen(path) + strlen(src) + 2, "do_find_source"); -#ifdef VMS - if (strcspn(path,">]:") == strlen(path)) - strcat(path, "/"); -#else - strcat(path, "/"); -#endif - strcat(path, src); - return path; - } - if (pi->awkpath == NULL) init_awkpath(pi); |