home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / MAKEPATH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.9 KB  |  89 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - makepath.c
  3.  *
  4.  * function(s)
  5.  *        _makepath - make new filename
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <string.h>
  18.  
  19. /*---------------------------------------------------------------------*
  20.  
  21. Name            _makepath - makes new file name
  22.  
  23. Usage           #include <stdlib.h>
  24.                 void _makepath(char *path, const char * drive, const char * dir,
  25.                              const char * name, const char * ext);
  26.  
  27. Related
  28. functions usage void _splitpath(const char *path, char *drive, char *dir,
  29.                             char *name, char *ext);
  30.  
  31. Prototype in    stdlib.h
  32.  
  33. Description     _makepath makes a file name from its components. The
  34.                 new file's full path name is
  35.  
  36.                         X:\DIR\SUBDIR\NAME.EXT
  37.  
  38.                 where
  39.  
  40.                         X is given by drive
  41.                         \DIR\SUBDIR\ is given by dir
  42.                         NAME.EXT is given by name and ext
  43.  
  44.                 If the drive, dir, name, or ext parameters are null or empty,
  45.                 they are not inserted in the path string.  Otherwise, if
  46.                 the drive doesn't end a colon, one is inserted in the path.
  47.                 If the dir doesn't end in a slash, one is inserted in the
  48.                 path.  If the ext doesn't start with a dot, one is inserted
  49.                 in the path.
  50.  
  51.                 The maximum sizes for the path string is given by the
  52.                 constant _MAX_PATH (defined in stdlib.h), which includes space
  53.                 for the null-terminator.
  54.  
  55.                 _splitpath and _makepath are invertible; if you split a given
  56.                 path with _splitpath, then merge the resultant components
  57.                 with _makepath, you end up with path.
  58.  
  59. Return value    None
  60.  
  61. *---------------------------------------------------------------------*/
  62.  
  63. void _FARFUNC _makepath(register char *pathP,
  64.                         const char *driveP,
  65.                         const char *dirP,
  66.                         const char *nameP,
  67.                         const char *extP
  68.                        )
  69. {
  70.         if (driveP && *driveP)
  71.             {
  72.                 *pathP++ = *driveP++;
  73.                 *pathP++ = ':';
  74.             }
  75.         if (dirP && *dirP)
  76.             {
  77.                 pathP = _stpcpy(pathP,dirP);
  78.                 if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '\\';
  79.             }
  80.         if (nameP)
  81.         pathP = _stpcpy(pathP,nameP);
  82.         if (extP && *extP)
  83.             {
  84.                 if (*extP != '.') *pathP++ = '.';
  85.                 pathP = _stpcpy(pathP,extP);
  86.             }
  87.         *pathP = 0;
  88. }
  89.