rev 197 - in trunk: modules/File pr
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bcollins
Date: 2004-03-29 12:33:21 -0500 (Mon, 29 Mar 2004)
New Revision: 197
Modified:
trunk/modules/File/File.c
trunk/pr/stdio_test.pr
Log:
Cleanup File.c a bit from previous changes.
Update stdio_test.pr for some extra checks.
Modified: trunk/modules/File/File.c
===================================================================
--- trunk/modules/File/File.c 2004-03-29 16:31:32 UTC (rev 196)
+++ trunk/modules/File/File.c 2004-03-29 17:33:21 UTC (rev 197)
@@ -112,7 +112,7 @@
apr_file_t *f;
apr_status_t aprerr;
apr_pool_t *subpool;
- apr_int32_t flags;
+ apr_int32_t flags = 0;
char *file, *mode;
char err_buf[1024];
@@ -136,6 +136,12 @@
file = strch(parms[1]);
mode = strch(parms[3]);
+ if ((mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') ||
+ (mode[1] != '+' && mode[1] != '\0')) {
+ raise_exception(ist, OBJ(TYPE_EXC), "File mode `%s' is not valid", mode);
+ return NULL;
+ }
+
if (mode[0] == 'r') {
flags = APR_READ;
if (mode[1] == '+')
@@ -148,9 +154,6 @@
flags = APR_WRITE | APR_CREATE | APR_APPEND;
if (mode[1] == '+')
flags |= APR_READ;
- } else {
- raise_exception(ist, OBJ(TYPE_EXC), "File mode is invalid");
- return NULL;
}
aprerr = apr_pool_create(&subpool, get_pr_head_pool());
@@ -167,7 +170,7 @@
return NULL;
}
- return new_file_object(parms[1], parms[3], f, (int)(parms[5]->data.i64, flags));
+ return new_file_object(parms[1], parms[3], f, (int)(parms[5]->data.i64), flags);
}
DEF(FILE_PROTO, __objlist__, FORM_RPARAM) {
Modified: trunk/pr/stdio_test.pr
===================================================================
--- trunk/pr/stdio_test.pr 2004-03-29 16:31:32 UTC (rev 196)
+++ trunk/pr/stdio_test.pr 2004-03-29 17:33:21 UTC (rev 197)
@@ -13,3 +13,10 @@
stdout.write("Hello " + name)
stderr.write("This is written on stderr\n")
+
+print "Opening test file for stdout"
+
+File.stdout = File("stdout.txt", "w+")
+
+stdout.write("Should still go to stdout\n")
+File.stdout.write("Should go to stdout.txt file\n")