Category : C Source Code
Archive   : RCS55SRC.ZIP
Filename : GETCWD.C

 
Output of file : GETCWD.C contained in archive : RCS55SRC.ZIP
// Alternative getcwd() for use with RCS as ported to Borland C++
//
// Returns path elements seperated by '/' rather than '\'
//

#include
#include
#include
#include
#include

static char RCSid[] = "$Id: getcwd.c%v 1.2 1991/08/23 13:26:54 SGP Exp $";

char *getcwd(char *buf, int buflen)
{
char buffer[MAXDIR+3];
char *s, *d, *rbuf = buf;
int drive = getdisk();

if (buf == NULL){
// malloc a buffer for the return value if one isn't supplied
if ((rbuf = (char *)malloc(MAXDIR+3)) == NULL){
errno = ENOMEM;
return (NULL);
}
}

if (getcurdir(0,buffer) < 0){
// Shouldn't fail - maybe no such device ?!?!?
errno = ENODEV;
return (NULL);
}

if (buflen-3 < (int)strlen(buffer)){
// No room in the return buffer
errno = ERANGE;
return (NULL);
}

// Set up the return value

rbuf[0] = tolower('A' + drive);
rbuf[1] = ':';
rbuf[2] = '/';

for (s = buffer, d = &rbuf[3]; *s != '\0'; s++)
*d++ = *s != '\\' ? tolower(*s) : '/';

*d = '\0';
errno = 0;
return (rbuf);
}


  3 Responses to “Category : C Source Code
Archive   : RCS55SRC.ZIP
Filename : GETCWD.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/