home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XS.ZIP / LIB / MKTEMPNM.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  3KB  |  81 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m k t e m p n m . c                                             */
  3. /*                                                                    */
  4. /*    Host Support routines for UUPC/extended                         */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of hlib.c                         ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <limits.h>
  16. #include <time.h>
  17.  
  18. #ifdef __GNUC__
  19. #include <unistd.h>
  20. #else
  21. #include <io.h>
  22. #endif
  23.  
  24. /*--------------------------------------------------------------------*/
  25. /*                          RCS Information                           */
  26. /*--------------------------------------------------------------------*/
  27.  
  28. /*
  29.  *    $Header: E:\SRC\UUPC\LIB\RCS\MKTEMPNM.C 1.2 1992/11/19 02:57:07 ahd Exp $
  30.  *
  31.  *    Revision history:
  32.  *    $Log: MKTEMPNM.C $
  33.  * Revision 1.2  1992/11/19  02:57:07  ahd
  34.  * drop rcsid
  35.  *
  36.  * Revision 1.1  1992/11/16  05:00:26  ahd
  37.  * Initial revision
  38.  *
  39.  */
  40.  
  41.  
  42. /*--------------------------------------------------------------------*/
  43. /*                    UUPC/extended include files                     */
  44. /*--------------------------------------------------------------------*/
  45.  
  46. #include "lib.h"
  47. #include "hlib.h"
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                          Global variables                          */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. currentfile();
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*    m k t e m p n a m e                                             */
  57. /*                                                                    */
  58. /*    Generate a temporary name with a pre-defined extension          */
  59. /*--------------------------------------------------------------------*/
  60.  
  61. char *mktempname( char *buf, char *extension)
  62. {
  63.    static size_t file = 0;
  64.    if (buf == NULL)           /* Do we need to allocate buffer?         */
  65.    {
  66.       buf = malloc( FILENAME_MAX );
  67.       checkref(buf);
  68.    } /* if */
  69.  
  70.    for (file++ ; file < INT_MAX ; file++ )
  71.    {
  72.       sprintf(buf,"%s/uupc%04.4x.%s", E_tempdir, file, extension);
  73.       if ( access( buf, 0 ))  /* Does the host file exist?           */
  74.          break;               /* No  --> Use the name                */
  75.    } /* for */
  76.  
  77.    printmsg(5,"Generated temporary name: %s",buf);
  78.    return buf;
  79.  
  80. } /* mktempname */
  81.