[Commit]
nickle file.c,1.49,1.50 nickle.h,1.103,1.104 value.h,1.86,1.87
Keith Packard
commit at keithp.com
Thu Jun 26 02:59:12 PDT 2003
Committed by: keithp
Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv4289
Modified Files:
file.c nickle.h value.h
Log Message:
Add File::reopen
Index: file.c
===================================================================
RCS file: /local/src/CVS/nickle/file.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- file.c 29 May 2003 18:36:35 -0000 1.49
+++ file.c 26 Jun 2003 08:59:09 -0000 1.50
@@ -682,6 +682,72 @@
}
Value
+FileReopen (char *name, char *mode, Value file, int *errp)
+{
+ ENTER ();
+ int oflags = 0;
+ int flags = 0;
+ int fd;
+
+ if (file->file.flags & FileString)
+ {
+ RaiseStandardException (exception_invalid_argument,
+ "Reopen: string file",
+ 2, file, Void);
+ RETURN (Void);
+ }
+
+ switch (mode[0]) {
+ case 'r':
+ if (mode[1] == '+')
+ {
+ flags |= FileWritable;
+ oflags = 2;
+ }
+ else
+ oflags = 0;
+ flags |= FileReadable;
+ break;
+ case 'w':
+ if (mode[1] == '+')
+ {
+ oflags = 2;
+ flags |= FileReadable;
+ }
+ else
+ oflags = 1;
+ oflags |= O_TRUNC|O_CREAT;
+ flags |= FileWritable;
+ break;
+ case 'a':
+ if (mode[1] == '+')
+ {
+ oflags = 2;
+ flags |= FileReadable;
+ }
+ else
+ oflags = 1;
+ oflags |= O_TRUNC|O_CREAT|O_APPEND;
+ flags |= FileWritable;
+ break;
+ }
+ fd = open (name, oflags, 0666);
+ if (fd < 0)
+ {
+ *errp = errno;
+ RETURN (0);
+ }
+ if (dup2 (fd, file->file.fd) < 0)
+ {
+ *errp = errno;
+ close (fd);
+ RETURN (0);
+ }
+ close (fd);
+ RETURN (file);
+}
+
+Value
FilePopen (char *program, char *argv[], char *mode, int *errp)
{
ENTER ();
Index: nickle.h
===================================================================
RCS file: /local/src/CVS/nickle/nickle.h,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- nickle.h 25 Jun 2003 19:49:14 -0000 1.103
+++ nickle.h 26 Jun 2003 08:59:10 -0000 1.104
@@ -1030,6 +1030,7 @@
Value do_File_vfprintf (Value, Value, Value);
Value do_String_substr (Value, Value, Value);
Value do_File_pipe (Value, Value, Value);
+Value do_File_reopen (Value, Value, Value);
/* four argument builtins */
Value do_Command_lex_input (Value file, Value name, Value after, Value interactive);
Index: value.h
===================================================================
RCS file: /local/src/CVS/nickle/value.h,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- value.h 11 Jun 2003 05:01:55 -0000 1.86
+++ value.h 26 Jun 2003 08:59:10 -0000 1.87
@@ -902,6 +902,7 @@
void FilePutPublish (Value f, Publish publish, Bool minimal);
void FilePutType (Value f, Type *t, Bool minimal);
Value FileFopen (char *name, char *mode, int *errp);
+Value FileReopen (char *name, char *mode, Value file, int *errp);
void FilePutArgType (Value f, ArgType *at);
Value FilePopen (char *program, char *args[], char *mode, int *errp);
int FileStatus (Value file);
More information about the Commit
mailing list