home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dmake40.zip / mac / tempnam.c < prev    next >
C/C++ Source or Header  |  1994-10-23  |  2KB  |  75 lines

  1. /* RCS      -- $Header: /u5/dvadura/src/public/dmake/src/mac/RCS/tempnam.c,v 1.1 1994/10/06 17:43:04 dvadura Exp $
  2. -- SYNOPSIS -- Fake tempnam function for the mac
  3. --
  4. -- DESCRIPTION
  5. --  Get a temporary file name.
  6. --
  7. -- AUTHOR
  8. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  9. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  10. --
  11. --
  12. -- COPYRIGHT
  13. --      Copyright (c) 1992,1994 by Dennis Vadura.  All rights reserved.
  14. -- 
  15. --      This program is free software; you can redistribute it and/or
  16. --      modify it under the terms of the GNU General Public License
  17. --      (version 1), as published by the Free Software Foundation, and
  18. --      found in the file 'LICENSE' included with this distribution.
  19. -- 
  20. --      This program is distributed in the hope that it will be useful,
  21. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  22. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. --      GNU General Public License for more details.
  24. -- 
  25. --      You should have received a copy of the GNU General Public License
  26. --      along with this program;  if not, write to the Free Software
  27. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. --
  29. -- LOG
  30. --     $Log: tempnam.c,v $
  31.  * Revision 1.1  1994/10/06  17:43:04  dvadura
  32.  * dmake Release Version 4.0, Initial revision
  33.  *
  34. */
  35.  
  36.  
  37. #include "extern.h"
  38. #include <StdIO.h>
  39. #include <String.h>
  40.  
  41.  
  42.  
  43. /*
  44.  * Try to open a temporary file in the given directory (if non-NULL)
  45.  * with the given prefix (if non-NULL).
  46.  *
  47.  * We ignore the directory argument.
  48.  */
  49. PUBLIC char *
  50. tempnam(char *pDir, char * pPrefix)
  51. {
  52.     char *pName;
  53.     char *pFullName;
  54.  
  55.     pName = tmpnam ((char *) NULL);
  56.  
  57.     /* Assume that if the name returned by tmpnam is not being used,
  58.        the name with the prefix is also not being used. */
  59.     pFullName = MALLOC (((pPrefix != NULL) ? strlen (pPrefix) : 0) +
  60.                         strlen (pName) + 1, char);
  61.  
  62.     /* Copy in the name if we successfully allocated space for it. */
  63.     if (pFullName != NULL) {
  64.         if (pPrefix != NULL) {
  65.             strcpy (pFullName, pPrefix);
  66.         } else {
  67.             *pFullName = '\0';
  68.         } /* if ... else */
  69.  
  70.         strcat (pFullName, pName);
  71.     } /* if */
  72.     
  73.     return (pFullName);
  74. } /* PUBLIC char *tempnam () */
  75.