X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/abd7f89523564e5e238e5852585b98f72c3b48f4..51b94abca5785eb36cc632a5f8c9ee3d5a6f5d06:/src/osd.c diff --git a/src/osd.c b/src/osd.c index 16f020d..3d75cf6 100644 --- a/src/osd.c +++ b/src/osd.c @@ -305,7 +305,7 @@ osd_fileExists (cstring filespec) return (stat (cstring_toCharsSafe (filespec), &buf) == 0); # else # if defined (WIN32) || defined (OS2) - FILE *test = fileTable_openFile (context_fileTable (), filespec, "r"); + FILE *test = fileTable_openReadFile (context_fileTable (), filespec); if (test != NULL) { @@ -453,8 +453,6 @@ nextdir (d_char *current_dir, d_char *dir, size_t *len) # endif } -# ifndef NOLCL - # ifdef WIN32 extern /*@external@*/ int _flushall (void) /*@modifies fileSystem@*/ ; # endif @@ -473,7 +471,6 @@ int osd_system (cstring cmd) res = system (cstring_toCharsSafe (cmd)); return res; } -# endif # ifndef unlink /* This should be defined by unistd.h */ @@ -567,7 +564,7 @@ cstring osd_fixDefine (cstring x) bool osd_fileIsReadable (cstring f) { - FILE *fl = fileTable_openFile (context_fileTable (), f, "r"); + FILE *fl = fileTable_openReadFile (context_fileTable (), f); if (fl != NULL) { @@ -888,6 +885,12 @@ void osd_initMod (void) osd_setWorkingDirectory (); } +void osd_destroyMod (void) +{ + cstring_free (osd_cwd); + osd_cwd = cstring_undefined; +} + cstring osd_absolutePath (cstring cwd, cstring filename) { # if defined (UNIX) || defined (OS2) @@ -1033,6 +1036,7 @@ cstring osd_absolutePath (cstring cwd, cstring filename) cstring osd_outputPath (cstring filename) { + /*@i2534 fix this junky code once and for all! */ # if defined (UNIX) || defined (OS2) char *rel_buffer; char *rel_buf_p; @@ -1041,11 +1045,12 @@ cstring osd_outputPath (cstring filename) int unmatched_slash_count = 0; size_t filename_len = cstring_length (filename); - llassertretval (filename_len > 0, /*@-type@*/ filename /*@=type@*/); + llassertretval (filename_len > 0, filename); /*@access cstring@*/ path_p = filename; - rel_buf_p = rel_buffer = (char *) dmalloc (filename_len); + rel_buffer = (char *) dmalloc (filename_len); + rel_buf_p = rel_buffer; *rel_buf_p = '\0'; llassert (cwd_p != NULL); @@ -1060,25 +1065,35 @@ cstring osd_outputPath (cstring filename) if ((*cwd_p == '\0') && (*path_p == '\0' || osd_isConnectChar (*path_p))) /* whole pwd matched */ { if (*path_p == '\0') /* input *is* the current path! */ - return cstring_makeLiteral ("."); + { + cstring_free (rel_buffer); + return cstring_makeLiteral ("."); + } else { /*@i324 ! splint didn't report an errors for: return ++path_p; */ - return cstring_fromCharsNew (++path_p); + cstring_free (rel_buffer); + return cstring_fromCharsNew (path_p + 1); } } else { + + /* drl 2002-10/14 I had to put this code back*/ + /* the case that needs it is when splint is given an absolute path name of a file outside of the current directory and the subdirectories below the current directory. e.g. cd /home/; splint /tmp/prog.c + */ + /* evans 2002-02-05 This is horrible code, which I've removed. I couldn't find any ** test cases that need it, so I hope I'm not breaking anything. */ + /*#if 0*/ -# if 0 if (*path_p != '\0') { --cwd_p; --path_p; - while (!osd_isConnectChar (*cwd_p)) /* backup to last slash */ + + while (cwd_p >= osd_cwd && !osd_isConnectChar (*cwd_p)) /* backup to last slash */ { --cwd_p; --path_p; @@ -1099,10 +1114,13 @@ cstring osd_outputPath (cstring filename) Reject it if longer than the input. */ if (unmatched_slash_count * 3 + strlen (path_p) >= filename_len) { + cstring_free (rel_buffer); + /* fprintf (stderr, "Returning filename: %s [%p]\n", filename); */ return cstring_copy (filename); } -# endif - + + /*drl 10-14-2002 end previously removed code */ + /*#endif*/ /* For each of them, put a `../' at the beginning of the short name. */ while (unmatched_slash_count-- > 0) { @@ -1120,6 +1138,7 @@ cstring osd_outputPath (cstring filename) } /* Then tack on the unmatched part of the desired file's name. */ + do { if (rel_buffer + filename_len <= rel_buf_p) @@ -1130,12 +1149,14 @@ cstring osd_outputPath (cstring filename) } /*@-usereleased@*/ while ((*rel_buf_p++ = *path_p++) != '\0') ; + /*@=usereleased@*/ /*@i523! shouldn't need these */ --rel_buf_p; if (osd_isConnectChar (*(rel_buf_p-1))) *--rel_buf_p = '\0'; + /* fprintf (stderr, "Returning buffer: %s [%p]\n", rel_buffer, rel_buffer); */ return rel_buffer; } /*@noaccess cstring@*/