home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / mktempnm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-29  |  5.1 KB  |  134 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m k t e m p n m . c                                             */
  3. /*                                                                    */
  4. /*    Host Support routines for UUPC/extended                         */
  5. /*                                                                    */
  6. /*--------------------------------------------------------------------*/
  7.  
  8. /*--------------------------------------------------------------------*/
  9. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  10. /*       Wonderworks.                                                 */
  11. /*                                                                    */
  12. /*       All rights reserved except those explicitly granted by       */
  13. /*       the UUPC/extended license agreement.                         */
  14. /*--------------------------------------------------------------------*/
  15.  
  16. /*--------------------------------------------------------------------*/
  17. /*                          RCS Information                           */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. /*
  21.  *    $Id: mktempnm.c 1.6 1993/10/30 02:29:46 ahd Exp $
  22.  *
  23.  *    Revision history:
  24.  *    $Log: mktempnm.c $
  25.  *     Revision 1.6  1993/10/30  02:29:46  ahd
  26.  *     Trim trailing slash from root directories
  27.  *
  28.  *     Revision 1.5  1993/10/12  00:45:27  ahd
  29.  *     Normalize comments
  30.  *
  31.  *     Revision 1.4  1993/06/06  15:04:05  ahd
  32.  *     Use process id for first temp file number
  33.  *
  34.  *     Revision 1.3  1993/04/11  00:31:04  ahd
  35.  *     Global edits for year, TEXT, etc.
  36.  *
  37.  * Revision 1.2  1992/11/19  02:57:07  ahd
  38.  * drop rcsid
  39.  *
  40.  * Revision 1.1  1992/11/16  05:00:26  ahd
  41.  * Initial revision
  42.  *
  43.  */
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                        System include files                        */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <limits.h>
  53. #include <time.h>
  54.  
  55. #include <io.h>
  56. #include <process.h>
  57.  
  58.  
  59. /*--------------------------------------------------------------------*/
  60. /*                    UUPC/extended include files                     */
  61. /*--------------------------------------------------------------------*/
  62.  
  63. #include "lib.h"
  64. #include "hlib.h"
  65.  
  66. /*--------------------------------------------------------------------*/
  67. /*                          Global variables                          */
  68. /*--------------------------------------------------------------------*/
  69.  
  70. currentfile();
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*    m k t e m p n a m e                                             */
  74. /*                                                                    */
  75. /*    Generate a temporary name with a pre-defined extension          */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. char *mktempname( char *buf, char *extension)
  79. {
  80.    static size_t file = 0;
  81.    boolean slash;
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*                   Initialize the file name counter                 */
  85. /*--------------------------------------------------------------------*/
  86.  
  87.    if ( file == 0 )
  88.       file = getpid() & 0x7FFF;  /* Make unique number less than 32K  */
  89.  
  90. /*--------------------------------------------------------------------*/
  91. /*                Allocate a file name buffer if required             */
  92. /*--------------------------------------------------------------------*/
  93.  
  94.    if (buf == NULL)           /* Do we need to allocate buffer?       */
  95.    {
  96.       buf = malloc( FILENAME_MAX );
  97.       checkref(buf);
  98.    } /* if */
  99.  
  100. /*--------------------------------------------------------------------*/
  101. /*       Determine if we need have a slash at the end of the file     */
  102. /*       name.  This should be reducible (only executed the first     */
  103. /*       pass) but since RNEWS and UUCICO play with the temporary     */
  104. /*       file name path to generate files in special directories,     */
  105. /*       we check every time.                                         */
  106. /*--------------------------------------------------------------------*/
  107.  
  108.    if ( E_tempdir[ strlen( E_tempdir ) - 1 ] == '/' )
  109.       slash = TRUE;
  110.    else
  111.       slash = FALSE;
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*        Loop looking for the non-existent file of our dreams        */
  115. /*--------------------------------------------------------------------*/
  116.  
  117.    for (file++ ; file < INT_MAX ; file++ )
  118.    {
  119.       sprintf(buf,"%s%suupc%04.4x.%s",
  120.                   E_tempdir,
  121.                   slash ? "" : "/",
  122.                   file,
  123.                   extension);
  124.  
  125.       if ( access( buf, 0 ))  /* Does the host file exist?            */
  126.          break;               /* No  --> Use the name                 */
  127.  
  128.    } /* for */
  129.  
  130.    printmsg(5,"Generated temporary name: %s",buf);
  131.    return buf;
  132.  
  133. } /* mktempname */
  134.