getcwd.c revision 75584
175584Sru/* Copyright (C) 2000 Free Software Foundation, Inc. 275584Sru Written by James Clark (jjc@jclark.com) 375584Sru 475584SruThis file is part of groff. 575584Sru 675584Srugroff is free software; you can redistribute it and/or modify it under 775584Sruthe terms of the GNU General Public License as published by the Free 875584SruSoftware Foundation; either version 2, or (at your option) any later 975584Sruversion. 1075584Sru 1175584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 1275584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 1375584SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1475584Srufor more details. 1575584Sru 1675584SruYou should have received a copy of the GNU General Public License along 1775584Sruwith groff; see the file COPYING. If not, write to the Free Software 1875584SruFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 1975584Sru 2075584Sru/* Partial emulation of getcwd in terms of getwd. */ 2175584Sru 2275584Sru#include <sys/param.h> 2375584Sru#include <string.h> 2475584Sru#include <errno.h> 2575584Sru 2675584Sruchar *getwd(); 2775584Sru 2875584Sruchar *getcwd(buf, size) 2975584Sru char *buf; 3075584Sru int size; /* POSIX says this should be size_t */ 3175584Sru{ 3275584Sru if (size <= 0) { 3375584Sru errno = EINVAL; 3475584Sru return 0; 3575584Sru } 3675584Sru else { 3775584Sru char mybuf[MAXPATHLEN]; 3875584Sru int saved_errno = errno; 3975584Sru 4075584Sru errno = 0; 4175584Sru if (!getwd(mybuf)) { 4275584Sru if (errno == 0) 4375584Sru ; /* what to do? */ 4475584Sru return 0; 4575584Sru } 4675584Sru errno = saved_errno; 4775584Sru if (strlen(mybuf) + 1 > size) { 4875584Sru errno = ERANGE; 4975584Sru return 0; 5075584Sru } 5175584Sru strcpy(buf, mybuf); 5275584Sru return buf; 5375584Sru } 5475584Sru} 55