| /* A part of the Windows CE C Extra Library (celibc) |
| Copyright 2007-2015 PC GO Ld. |
| |
| This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| */ |
| |
| #include <stdio.h> |
| #include <errno.h> |
| #include <string.h> |
| |
| #if 1 |
| char *strerror_r(int, char *, size_t); |
| #endif |
| |
| char *getcwd(char *buf, size_t size) { |
| if(size == 0) { |
| if(buf) { |
| errno = EINVAL; |
| return NULL; |
| } |
| //char *path = malloc(2 * sizeof(char)); |
| //path[0] = '/'; |
| //path[1] = '\0'; |
| //return path; |
| buf = malloc(2 * sizeof(char)); |
| } else if(size < 2) { |
| errno = ERANGE; |
| return NULL; |
| } |
| buf[0] = '/'; |
| buf[1] = 0; |
| return buf; |
| } |
| |
| char *getwd(char *buf) { |
| #ifndef PATH_MAX |
| #define PATH_MAX 256 |
| #endif |
| char tmpbuf[PATH_MAX]; |
| |
| if(!buf){ |
| errno = EINVAL; |
| return NULL; |
| } |
| if(!getcwd(tmpbuf, PATH_MAX)) { |
| strerror_r(errno, buf, 1024); |
| return NULL; |
| } |
| |
| /* This is completely unsafe. Nobody can say how big the user |
| provided buffer is. Perhaps the application and the libc |
| disagree about the value of PATH_MAX. */ |
| return strcpy(buf, tmpbuf); |
| } |