home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / compat / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-18  |  1.1 KB  |  50 lines

  1. /* 
  2.  * getcwd.c --
  3.  *
  4.  *    This file provides an implementation of the getcwd procedure
  5.  *    that uses getwd, for systems with getwd but without getcwd.
  6.  *
  7.  * Copyright (c) 1993 The Regents of the University of California.
  8.  * Copyright (c) 1994 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  */
  13.  
  14. #ifndef lint
  15. static char sccsid[] = "@(#) getcwd.c 1.4 94/12/17 16:26:18";
  16. #endif /* not lint */
  17.  
  18. #include "tclInt.h"
  19. #include "tclPort.h"
  20.  
  21. extern char *getwd _ANSI_ARGS_((char *pathname));
  22.  
  23. char *
  24. getcwd(buf, size)
  25.     char *buf;            /* Where to put path for current directory. */
  26.     size_t size;        /* Number of bytes at buf. */
  27. {
  28.     char realBuffer[MAXPATHLEN+1];
  29.     int length;
  30.  
  31.     if (getwd(realBuffer) == NULL) {
  32.     /*
  33.      * There's not much we can do besides guess at an errno to
  34.      * use for the result (the error message in realBuffer isn't
  35.      * much use...).
  36.      */
  37.  
  38.     errno = EACCES;
  39.     return NULL;
  40.     }
  41.     length = strlen(realBuffer);
  42.     if (length >= size) {
  43.     errno = ERANGE;
  44.     return NULL;
  45.     }
  46.     strcpy(buf, realBuffer);
  47.     return buf;
  48. }
  49.  
  50.