#include <sys/types.h>#include <sys/stat.h>#include <errno.h>#include "lclintMacros.nf"#include "basic.h"#include "osd.h"#include "portab.h"Go to the source code of this file.
Functions | |
| int | stat (const char *, struct stat *) |
| char* | LSLRootName (char *filespec) |
| char* | osd_getEnvironment (char *env, char *def) |
| char* | osd_getHomeDir () |
| filestatus | osd_findOnLarchPath (char *file, char **returnPath) |
| filestatus | osd_getPath (char *path, char *file, char **returnPath) |
| filestatus | osd_getExePath (char *path, char *file, char **returnPath) |
| bool | osd_fileExists (char *filespec) |
| char* | osd_getEnvironmentVariable (char *var) |
| int | system (const char *) |
| int | osd_system (const char *cmd) |
| int | unlink (const char *) |
| int | osd_unlink (const char *fname) |
| int | osd_getPid () |
| cstring | osd_fixDefine (char *x) |
| bool | osd_fileIsReadable (char *f) |
| bool | osd_isConnectChar (char c) |
|
|
Definition at line 65 of file osd.c. Referenced by lhInit(). 00066 {
00067 char *result, *startName, *tail;
00068 size_t nameLength;
00069
00070 tail = strrchr (filespec, CONNECTCHAR);
00071 startName = (tail == NULL ? filespec : &tail[1]);
00072 tail = strrchr (startName, '.');
00073 nameLength = (tail == NULL ? strlen (startName)
00074 : size_fromInt (tail - startName));
00075 result = dmalloc (nameLength + 1);
00076 strncpy (result, startName, nameLength);
00077 result[(int) nameLength] = '\0';
00078 return result;
00079 }
|
|
|
Definition at line 268 of file osd.c. Referenced by osd_getExePath(), and osd_getPath(). 00269 {
00270 # ifdef UNIX
00271 struct stat buf;
00272 return (stat (filespec, &buf) == 0);
00273 # else
00274 # if defined (WIN32) || defined (OS2)
00275 FILE *test = fopen (filespec, "r");
00276 if (test != NULL)
00277 {
00278 (void) fclose (test);
00279 return TRUE;
00280 }
00281 else
00282 {
00283 return FALSE;
00284 }
00285 # else
00286 return FALSE;
00287 # endif
00288 # endif
00289 }
|
|
|
Definition at line 513 of file osd.c. 00514 {
00515 FILE *fl = fopen (f, "r");
00516
00517 if (fl != (FILE *) 0)
00518 {
00519 check (fclose (fl) == 0);
00520 return (TRUE);
00521 }
00522 else
00523 {
00524 return (FALSE);
00525 }
00526 }
|
|
|
Definition at line 138 of file osd.c. Referenced by importCTrait(), and loadStandardState(). 00139 {
00140 return (osd_getPath (cstring_toCharsSafe (context_getLarchPath ()), file, returnPath));
00141 }
|
|
|
Definition at line 475 of file osd.c. 00476 {
00477 # ifdef UNIX
00478 if (strchr (x, '\'') != NULL) {
00479 /*
00480 ** If there is a single quote, check for <ident>='<string>' and
00481 ** produce <ident>=<string>
00482 */
00483
00484 char *eqs = strchr (x, '=');
00485
00486 if (eqs != NULL) {
00487 if (eqs[1] == '\'') {
00488 char *endqu = strrchr (x, '\'');
00489
00490 if (endqu != NULL) {
00491 if (*(endqu - 1) != '\\') {
00492 if (*(endqu + 1) == '\0') {
00493 cstring res;
00494 cstring def;
00495
00496 *endqu = '\0';
00497 def = cstring_fromChars (eqs + 2);
00498 eqs[1] = '\0';
00499 res = cstring_concat (cstring_fromChars (x), def);
00500 return res;
00501 }
00502 }
00503 }
00504 }
00505 }
00506 }
00507
00508 # endif
00509
00510 return cstring_fromCharsNew (x);
00511 }
|
|
|
Definition at line 82 of file osd.c. 00083 {
00084 char *ret = osd_getEnvironmentVariable (env);
00085
00086 if (ret == NULL)
00087 {
00088 return def;
00089 }
00090 else
00091 {
00092 return ret;
00093 }
00094 }
|
|
|
Definition at line 392 of file osd.c. Referenced by context_resetAllFlags(), osd_getEnvironment(), osd_getExePath(), and osd_getHomeDir(). 00393 {
00394 # ifdef UNIX
00395 return getenv (var);
00396 # else
00397 # if defined(OS2) || defined(MSDOS)
00398 return getenv (var);
00399 # else
00400 # if defined(WIN32)
00401 return getenv (var);
00402 # else
00403 return NULL;
00404 # endif
00405 # endif
00406 # endif
00407 }
|
|
|
Definition at line 209 of file osd.c. 00210 {
00211 char *fullPath;
00212 char *dirPtr;
00213 size_t dirLen;
00214 char aPath[MAXPATHLEN];
00215 filestatus rVal = OSD_FILENOTFOUND; /* assume file not found. */
00216
00217 fullPath = osd_getEnvironmentVariable (path);
00218
00219 if (fullPath == NULL)
00220 {
00221 /* No path specified. Look for it in the current directory. */
00222
00223 strcpy (&aPath[0], file);
00224
00225 if (osd_fileExists (&aPath[0]))
00226 {
00227 rVal = OSD_FILEFOUND;
00228 *returnPath = dmalloc (strlen (&aPath[0]) + 1);
00229 strcpy (*returnPath, &aPath[0]);
00230 }
00231 }
00232 else
00233 {
00234 /*
00235 ** Path specified. Loop through directories in path looking
00236 ** for the first occurrence of the file.
00237 */
00238
00239 while (nextdir (&fullPath, &dirPtr, &dirLen) &&
00240 rVal == OSD_FILENOTFOUND)
00241 {
00242 if ((dirLen + strlen (file) + 2) <= MAXPATHLEN)
00243 {
00244 /* Cat directory and filename, and see if file exists. */
00245 strncpy (&aPath[0], dirPtr, dirLen);
00246 strcpy (&aPath[0] + dirLen, ""); /* Null terminate aPath. */
00247 strcat (&aPath[0], CONNECTSTR);
00248 strcat (&aPath[0], file);
00249
00250 if (osd_executableFileExists (&aPath[0]))
00251 {
00252 rVal = OSD_FILEFOUND;
00253 *returnPath = dmalloc (strlen (&aPath[0]) + 1);
00254 strcpy (*returnPath, &aPath[0]);
00255 }
00256 }
00257 else
00258 {
00259 rVal = OSD_PATHTOOLONG;
00260 }
00261 }
00262 }
00263
00264 return rVal;
00265 }
|
|
|
Definition at line 132 of file osd.c. 00133 {
00134 /* Would something different be better for windows? */
00135 return (osd_getEnvironmentVariable ("HOME"));
00136 }
|
|
|
Definition at line 144 of file osd.c. Referenced by osd_findOnLarchPath(), processImport(), and tsource_getPath(). 00145 {
00146 char *fullPath;
00147 char *dirPtr;
00148 size_t dirLen;
00149 char aPath[MAXPATHLEN];
00150 filestatus rVal = OSD_FILENOTFOUND; /* assume file not found. */
00151
00152 fullPath = path;
00153
00154 if (fullPath == NULL ||
00155 # if defined(OS2) || defined(MSDOS) || defined(WIN32)
00156 /* under OS/2 and MSDOS the includePath may be empty, if so, search
00157 * the current directory. */
00158 *fullPath == '\0' ||
00159 (*file == CONNECTCHAR || (file[0] != '\0' && file[1] == ':')))
00160 # else
00161 (*file == CONNECTCHAR))
00162 # endif
00163 {
00164 /* No path specified. Look for it in the current directory. */
00165
00166 strcpy (&aPath[0], file);
00167
00168 if (osd_fileExists (&aPath[0]))
00169 {
00170 rVal = OSD_FILEFOUND;
00171 *returnPath = dmalloc (strlen (&aPath[0]) + 1);
00172 strcpy (*returnPath, &aPath[0]);
00173 }
00174 }
00175 else
00176 {
00177 /* Path specified. Loop through directories in path looking for the */
00178 /* first occurrence of the file. */
00179
00180 while (nextdir (&fullPath, &dirPtr, &dirLen) &&
00181 rVal == OSD_FILENOTFOUND)
00182 {
00183 if ((dirLen + strlen (file) + 2) <= MAXPATHLEN)
00184 {
00185 /* Cat directory and filename, and see if file exists. */
00186 strncpy (&aPath[0], dirPtr, dirLen);
00187 strcpy (&aPath[0] + dirLen, ""); /* Null terminate aPath. */
00188 strcat (&aPath[0], CONNECTSTR);
00189 strcat (&aPath[0], file);
00190
00191 if (osd_fileExists (&aPath[0]))
00192 {
00193 rVal = OSD_FILEFOUND;
00194 *returnPath = (char *) dmalloc (strlen (&aPath[0]) + 1);
00195 strcpy (*returnPath, &aPath[0]);
00196 }
00197 }
00198 else
00199 {
00200 rVal = OSD_PATHTOOLONG;
00201 }
00202 }
00203 }
00204
00205 return rVal;
00206 }
|
|
|
Definition at line 464 of file osd.c. 00465 {
00466 # if defined (WIN32) || defined (OS2) && defined (__IBMC__)
00467 int pid = _getpid ();
00468 # else
00469 pid_t pid = getpid ();
00470 # endif
00471
00472 return (int) pid;
00473 }
|
|
|
Definition at line 528 of file osd.c. Referenced by cstring_equalCanonicalPrefix(). 00529 {
00530 if (c == CONNECTCHAR)
00531 {
00532 return TRUE;
00533 }
00534
00535 # ifdef HASALTCONNECTCHAR
00536 if (c == ALTCONNECTCHAR)
00537 {
00538 return TRUE;
00539 }
00540 # endif
00541
00542 return FALSE;
00543 }
|
|
|
Definition at line 418 of file osd.c. 00419 {
00420 int res;
00421 /* system ("printenv"); */
00422 # ifdef WIN32
00423 (void) _flushall ();
00424 # endif
00425
00426 res = system (cmd);
00427 return res;
00428 }
|
|
|
Definition at line 437 of file osd.c. Referenced by fileTable_cleanup(), and lhCleanup(). 00438 {
00439 int res;
00440
00441 res = unlink (fname);
00442
00443 if (res != 0)
00444 {
00445 llcontbug (message ("Cannot remove temporary file: %s (%s)",
00446 cstring_fromChars (fname),
00447 cstring_fromChars (strerror (errno))));
00448 }
00449
00450 return res;
00451 }
|
|
|
Referenced by osd_fileExists(). |
|
|
Referenced by osd_system(). |
|
|
Referenced by osd_unlink(). |
1.2.3 written by Dimitri van Heesch,
© 1997-2000