File-Names.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <html lang="en">
  2. <head>
  3. <title>File Names - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="File-Manipulation.html#File-Manipulation" title="File Manipulation">
  9. <link rel="prev" href="File-Manipulation.html#File-Manipulation" title="File Manipulation">
  10. <link rel="next" href="Raw-Files.html#Raw-Files" title="Raw Files">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="File-Names"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Raw-Files.html#Raw-Files">Raw Files</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="File-Manipulation.html#File-Manipulation">File Manipulation</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="File-Manipulation.html#File-Manipulation">File Manipulation</a>
  32. <hr>
  33. </div>
  34. <h4 class="subsection">3.3.1 File Names</h4>
  35. <p>A standard representation is used by virtual code applications for the
  36. <a name="index-file-names-528"></a>path names of files, following the description in <a href="Input-Data-Structure.html#Input-Data-Structure">Input Data Structure</a>. The functions and constants declared in <code>fnames.h</code>
  37. provide an API for operating on file names in this form.
  38. <div class="defun">
  39. &mdash; Function: list <b>avm_path_representation</b> (<var>char *path</var>)<var><a name="index-avm_005fpath_005frepresentation-529"></a></var><br>
  40. <blockquote><p>If a C program is to invoke a virtual code application and pass a path
  41. name to it as a parameter, this function can be used to generate the
  42. appropriate representation from a given character string.
  43. <pre class="example"> conf_path = avm_path_representation("/etc/resolve.conf");
  44. </pre>
  45. <p>In this example, <code>conf_path</code> is a <code>list</code>. For potentially
  46. better portability, a C program can use the character constant
  47. <code>avm_path_separator_character</code> in place of the slashes in hard
  48. coded path names.
  49. <p>Other useful constants are <code>avm_current_directory_prefix</code> as a
  50. <a name="index-g_t_0040code_007bavm_005fpath_005fseparator_005fcharacter_007d-530"></a><a name="index-g_t_0040code_007bavm_005fpath_005fseparator_007d-531"></a><a name="index-g_t_0040code_007bavm_005fcurrent_005fdirectory_005fprefix_007d-532"></a><a name="index-g_t_0040code_007bavm_005fparent_005fdirectory_005fprefix_007d-533"></a><a name="index-g_t_0040code_007bavm_005froot_005fdirectory_005fprefix_007d-534"></a>portable replacement for <code>"./"</code>, as well as
  51. <code>avm_parent_directory_prefix</code> instead of <code>"../"</code>. There is
  52. also <code>avm_root_directory_prefix</code> for <code>"/"</code>. These three
  53. constants are null terminated strings, unlike
  54. <code>avm_path_separator_character</code>, which is a character.
  55. <p>If a <code>NULL</code> pointer is passed as the <var>path</var>, a
  56. <code>NULL</code> list is returned, which is the path representation for
  57. standard input or standard output. If the address of an empty string is
  58. passed to this function as the <var>path</var>, the list of the empty
  59. string will be returned, which is the path representation for the root
  60. directory. Trailing path separators are ignored, so <code>"/"</code> is the
  61. same as the empty string.
  62. <p>Some memory needs to be allocated for the result of this function. If
  63. the memory is not available, an error message is written to standard
  64. error and the process is terminated.
  65. </p></blockquote></div>
  66. <div class="defun">
  67. &mdash; Function: list <b>avm_date_representation</b> (<var>char *path</var>)<var><a name="index-avm_005fdate_005frepresentation-535"></a></var><br>
  68. <blockquote><p>This function is essentially a wrapper around the standard
  69. <code>ctime_r</code> function that not only gets the time stamp for a file at
  70. a given path, but transforms it to a list representation according to
  71. <a href="Character-Table.html#Character-Table">Character Table</a>. It needs to allocate memory for the result and
  72. will cause the program to exit with an error message if there is not
  73. enough memory available.
  74. <p>The time stamp will usually be in a format like <code>Sun Mar 4 10:56:40
  75. GMT 2001</code>. If for some reason the time stamp can not be obtained, the
  76. <a name="index-g_t_0040code_007bunknown-date_007d-536"></a>result will be a representation of the string <code>unknown date</code>.
  77. </p></blockquote></div>
  78. <div class="defun">
  79. &mdash; Function: char* <b>avm_path_name</b> (<var>list path</var>)<var><a name="index-avm_005fpath_005fname-537"></a></var><br>
  80. <blockquote><p>This function is the inverse of <code>avm_path_representation</code>, in that
  81. it takes a list representing a path to the path name expressed as a character
  82. string. This function can be used in C programs that invoke virtual code
  83. applications returning paths as part of their results, so that the C
  84. program can get the path into a character string in order to open the file.
  85. <p>If the <var>path</var> parameter is <code>NULL</code>, a <code>NULL</code> pointer
  86. is returned as the result. The calling program should check for a
  87. <a name="index-standard-input-538"></a><a name="index-standard-output-539"></a><code>NULL</code> result and interpret it as the path to standard input or
  88. standard output.
  89. <p>The memory needed for the character string whose address is returned is
  90. allocated by this function if possible. The given <var>path</var> is
  91. not required to be consistent with the host file system, but it is
  92. required to consist of representations of non-null printable characters
  93. or spaces as lists per <a href="Character-Table.html#Character-Table">Character Table</a>. In the event of any error
  94. or overflow, control does not return to the caller, but an error message
  95. is printed and the program is aborted. The possible error messages from
  96. this function are the following.
  97. <a name="index-g_t_0040code_007bcounter-overflow_007d-540"></a><a name="index-g_t_0040code_007bmemory-overflow_007d-541"></a><a name="index-g_t_0040code_007bnull-character-in-file-name_007d-542"></a><a name="index-g_t_0040code_007bbad-character-in-file-name_007d-543"></a><a name="index-g_t_0040code_007binvalid-file-name_007d-544"></a>
  98. <ul>
  99. <li><var>program-name</var><code>: counter overflow (code </code><var>nn</var><code>)</code>
  100. <li><var>program-name</var><code>: memory overflow (code </code><var>nn</var><code>)</code>
  101. <li><var>program-name</var><code>: null character in file name</code>
  102. <li><var>program-name</var><code>: bad character in file name</code>
  103. <li><var>program-name</var><code>: invalid file name (code </code><var>nn</var><code>)</code>
  104. </ul>
  105. </blockquote></div>
  106. <div class="defun">
  107. &mdash; Function: void <b>avm_initialize_fnames</b> ()<var><a name="index-avm_005finitialize_005ffnames-545"></a></var><br>
  108. <blockquote><p>A few housekeeping operations relevant to internal data structures are
  109. performed by this function, making it necessary to be called by the
  110. client program prior to using any of the other ones.
  111. </p></blockquote></div>
  112. <div class="defun">
  113. &mdash; Function: void <b>avm_count_fnames</b> ()<var><a name="index-avm_005fcount_005ffnames-546"></a></var><br>
  114. <blockquote><p>This function can be used after the the last call to any of the other
  115. functions in this section during a run, and it will detect memory leaks
  116. that may be attributable to code in these functions or misuse
  117. thereof. If any unreclaimed storage remains when this function is
  118. called, a warning message will be written to standard error. If the
  119. function <code>avm_count_lists</code> is also being used by the client, it
  120. should be called after this one.
  121. </p></blockquote></div>
  122. </body></html>