aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-04-08 19:23:52 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-04-08 19:23:52 +0300
commitacdfa6d81af4d9069e609780750f6dd8f98d6bff (patch)
treec863ffb717b373adf882d40d10af29f3f0128ddb /io.c
parent98837e032b31aeb9f358edaedda1440a450c9c1d (diff)
downloadegawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.tar.gz
egawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.tar.bz2
egawk-acdfa6d81af4d9069e609780750f6dd8f98d6bff.zip
Enable special filenames for profiling output.
Diffstat (limited to 'io.c')
-rw-r--r--io.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/io.c b/io.c
index 1d15d887..2344c2ad 100644
--- a/io.c
+++ b/io.c
@@ -1551,12 +1551,8 @@ nextrres:
}
#endif /* HAVE_SOCKETS */
-/* devopen --- handle /dev/std{in,out,err}, /dev/fd/N, regular files */
-/*
- * Strictly speaking, "name" is not a "const char *" because we temporarily
- * change the string.
- */
+/* devopen_simple --- handle "-", /dev/std{in,out,err}, /dev/fd/N */
/*
* 9/2014: Flow here is a little messy.
@@ -1570,22 +1566,25 @@ nextrres:
*/
int
-devopen(const char *name, const char *mode)
+devopen_simple(const char *name, const char *mode, bool try_real_open)
{
int openfd;
char *cp;
char *ptr;
int flag = 0;
- struct inet_socket_info isi;
- if (strcmp(name, "-") == 0)
- return fileno(stdin);
+ if (strcmp(name, "-") == 0) {
+ if (mode[0] == 'r')
+ return fileno(stdin);
+ else
+ return fileno(stdout);
+ }
flag = str2mode(mode);
openfd = INVALID_HANDLE;
if (do_posix)
- goto strictopen;
+ goto done;
if ((openfd = os_devopen(name, flag)) != INVALID_HANDLE) {
os_close_on_exec(openfd, name, "file", "");
@@ -1602,7 +1601,7 @@ devopen(const char *name, const char *mode)
else if (strcmp(cp, "stderr") == 0 && (flag & O_ACCMODE) == O_WRONLY)
openfd = fileno(stderr);
else if (do_traditional)
- goto strictopen;
+ goto done;
else if (strncmp(cp, "fd/", 3) == 0) {
struct stat sbuf;
@@ -1613,9 +1612,36 @@ devopen(const char *name, const char *mode)
openfd = INVALID_HANDLE;
}
/* do not set close-on-exec for inherited fd's */
- if (openfd != INVALID_HANDLE)
- return openfd;
- } else if (do_traditional) {
+ }
+done:
+ if (try_real_open)
+ openfd = open(name, flag, 0666);
+
+ return openfd;
+}
+
+/* devopen --- handle /dev/std{in,out,err}, /dev/fd/N, /inet, regular files */
+
+/*
+ * Strictly speaking, "name" is not a "const char *" because we temporarily
+ * change the string.
+ */
+
+int
+devopen(const char *name, const char *mode)
+{
+ int openfd;
+ char *cp;
+ int flag;
+ struct inet_socket_info isi;
+
+ openfd = devopen_simple(name, mode, false);
+ if (openfd != INVALID_HANDLE)
+ return openfd;
+
+ flag = str2mode(mode);
+
+ if (do_traditional) {
goto strictopen;
} else if (inetfile(name, & isi)) {
#ifdef HAVE_SOCKETS
@@ -1683,7 +1709,7 @@ strictopen:
not permitted. */
struct stat buf;
- if (!inetfile(name, NULL)
+ if (! inetfile(name, NULL)
&& stat(name, & buf) == 0 && S_ISDIR(buf.st_mode))
errno = EISDIR;
}