pathopen.txt
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:2k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. SUMMARY pathopen findpath
  2. #include <tools.h>
  3. flagType findpath(pstrFile, pbuf, fNew)
  4. char *pstrFile;
  5. char *pbuf;
  6. flagType fNew;
  7. FILE *pathopen(pstrName, pbuf, pmode)
  8. char *pstrName;
  9. char *pbuf;
  10. char *pmode;
  11. DESCRIPTION
  12. findpath tries to find the file specified by pstrFile.  If pstrFile is of
  13. the form $FOO:BAR where FOO is an environment variable each directory in the
  14. environment variable is searched else the current directory is searched.
  15. If the file is found and pbuf is filled in with the expanded path name and
  16. nonzero is returned.
  17. If the file is not found and fnew is FALSE, zero is returned
  18. If the file is not found and fnew is TRUE pbuf is filled in with the filename
  19. suitable for creating a new file and nonzero is returned, i.e. if pstrFile
  20. is of the form $FOO:BAR, the first directory in the environment variable FOO
  21. is used to create the filename.
  22. E.g.
  23.     PATH:C:BIN;C:MYBIN;
  24. if
  25.     findpath("$PATH:BAR", buf, TRUE);
  26. returns nonzero if BAR exists in C:BIN or C:MYBIN and buf contains either
  27. C:BINBAR or C:BINBAR; returns zero if BAR does not exist in either and
  28. contents of bar are undefined.
  29.     findpath("$PATH:BAR", buf, FALSE);
  30. always returns nonzero, buf is equal to C:BINBAR or C:BINBAR if it exists
  31. or C:BINBAR if it doesn't exist in both.  (Note: stat(buf, pstatBuf) can
  32. be used to determine if the file exists.)
  33. pathopen expands pstrName to pbuf using findpath with fnew == TRUE and if
  34. it succeeds calls the C library routine fopen with pbuf and mode and returns
  35. the value returned by fopen.  If the call to findpath fails NULL is returned
  36. by pathopen.
  37. RETURN VALUE
  38. See above.
  39. IMPLEMENTATION
  40. SEE ALSO   fopen (C runtime)
  41. NOTE
  42. In findpath, pbuf must point to a buffer large enough to hold the expanded
  43. pathname, e.g. buf[MAXPATHLEN].
  44. EXAMPLE
  45. #include <tools.h>
  46. main(c, argv)
  47. int c;
  48. char *argv[];
  49. {
  50.     char str[MAXPATHLEN];
  51.     flagType f;
  52.     f = findpath("$USER:\tools.ini", str, TRUE ); printf("%d %sn", f, str);
  53.     f = findpath("$USER:\tools.tmp", str, TRUE ); printf("%d %sn", f, str);
  54.     f = findpath("$USER:\tools.tmp", str, FALSE); printf("%d %sn", f, str);
  55.     f = findpath("test.c", str, TRUE ); printf("%d %sn", f, str);
  56. }
  57. give the output assuming SET USER=C:DANL and TOOLS.INI does exist, TOOLS.TMP
  58. does not exist in C:DANL and TEST.C exists in current directory.
  59. -1 c:danltools.ini
  60. -1 c:danltools.tmp
  61.  0 c:danltools.tmp
  62. -1 test.c