/[meta-cvs]/meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c
ViewVC logotype

Diff of /meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by kaz, Sat Aug 31 20:53:13 2002 UTC revision 1.4.2.6 by kaz, Sun Feb 2 03:31:35 2003 UTC
# Line 6  Line 6 
6  #include <unistd.h>  #include <unistd.h>
7  #include <sys/types.h>  #include <sys/types.h>
8  #include <sys/stat.h>  #include <sys/stat.h>
9    #include <sys/wait.h>
10    
11  /*  /*
12   * Null pointer test   * Null pointer test
13   */   */
14    
15  int impl_null_pointer_p(void *ptr)  int mcvs_null_pointer_p(void *ptr)
16  {  {
17    return ptr == 0;    return ptr == 0;
18  }  }
# Line 20  int impl_null_pointer_p(void *ptr) Line 21  int impl_null_pointer_p(void *ptr)
21   * <errno.h> stuff   * <errno.h> stuff
22   */   */
23    
24  int impl_get_errno(void)  int mcvs_get_errno(void)
25  {  {
26    return errno;    return errno;
27  }  }
28    
29  int impl_set_errno(int value)  int mcvs_set_errno(int value)
30  {  {
31    return errno = value;    return errno = value;
32  }  }
# Line 37  int impl_set_errno(int value) Line 38  int impl_set_errno(int value)
38  typedef struct {  typedef struct {
39    unsigned long d_ino;    unsigned long d_ino;
40    char d_name[1024];    char d_name[1024];
41  } impl_dirent;  } mcvs_dirent;
42    
43  impl_dirent *impl_readdir(DIR *dir)  mcvs_dirent *mcvs_readdir(DIR *dir)
44  {  {
45    static impl_dirent dw;    static mcvs_dirent dw;
46    struct dirent *de = readdir(dir);    struct dirent *de = readdir(dir);
47    if (de != 0) {    if (de != 0) {
48      strncpy(dw.d_name, de->d_name, sizeof dw.d_name - 1);      strncpy(dw.d_name, de->d_name, sizeof dw.d_name - 1);
# Line 55  impl_dirent *impl_readdir(DIR *dir) Line 56  impl_dirent *impl_readdir(DIR *dir)
56   * <unistd.h> stuff   * <unistd.h> stuff
57   */   */
58    
59  char *impl_readlink(const char *path)  char *mcvs_readlink(const char *path)
60  {  {
61    size_t size = 256;    size_t size = 256;
62    char *str = malloc(size);    char *str = malloc(size);
# Line 92  bail: Line 93  bail:
93   * <sys/stat.h> stuff   * <sys/stat.h> stuff
94   */   */
95    
96  struct impl_stat {  struct mcvs_stat {
97    unsigned long dev;    unsigned long dev;
98    unsigned long ino;    unsigned long ino;
99    unsigned long mode;    unsigned long mode;
# Line 107  struct impl_stat { Line 108  struct impl_stat {
108    unsigned long ctime;    unsigned long ctime;
109  };  };
110    
111  static void stat_to_impl(struct impl_stat *out, const struct stat *in)  static void stat_to_wrap(struct mcvs_stat *out, const struct stat *in)
112  {  {
113    out->dev = in->st_dev;    out->dev = in->st_dev;
114    out->ino = in->st_ino;    out->ino = in->st_ino;
# Line 124  static void stat_to_impl(struct impl_sta Line 125  static void stat_to_impl(struct impl_sta
125  }  }
126    
127  #define IMPL_STAT(FUNC, ARGTYPE) \  #define IMPL_STAT(FUNC, ARGTYPE) \
128  int impl_ ## FUNC(ARGTYPE arg, struct impl_stat *buf) \  int mcvs_ ## FUNC(ARGTYPE arg, struct mcvs_stat *buf) \
129  { \  { \
130    struct stat sbuf; \    struct stat sbuf; \
131    int retval = FUNC(arg, &sbuf); \    int retval = FUNC(arg, &sbuf); \
132    if (retval == 0) \    if (retval == 0) \
133      stat_to_impl(buf, &sbuf); \      stat_to_wrap(buf, &sbuf); \
134    return retval; \    return retval; \
135  }  }
136    
# Line 141  IMPL_STAT(fstat, int) Line 142  IMPL_STAT(fstat, int)
142   * <unistd.h> -- getcwd   * <unistd.h> -- getcwd
143   */   */
144    
145  const char *impl_getcwd(void)  const char *mcvs_getcwd(void)
146  {  {
147    size_t size = 256;    size_t size = 256;
148    char *str = malloc(size);    char *str = malloc(size);
# Line 151  const char *impl_getcwd(void) Line 152  const char *impl_getcwd(void)
152      goto bail;      goto bail;
153    
154    while (getcwd(str, size) == 0) {    while (getcwd(str, size) == 0) {
155        if (errno != ERANGE)
156          goto bail;
157      if (size * 2 < size)      if (size * 2 < size)
158        goto bail;        goto bail;
159      size *= 2;      size *= 2;
# Line 166  bail: Line 169  bail:
169    free(str);    free(str);
170    return 0;    return 0;
171  }  }
172    
173    /*
174     * <unistd.h> -- fork, wait*, exec*
175     */
176    
177    #ifdef __CYGWIN__
178    
179    /*
180     * waitpid is broken garbage on Cygwin, so we use its spawnvp function
181     * instead!
182     */
183    
184    #include <process.h>
185    int mcvs_spawn(const char *name, const char *const *argv)
186    {
187      return spawnvp(_P_WAIT, name, argv);
188    }
189    #else
190    int mcvs_spawn(const char *name, char *const *argv)
191    {
192      int result = -1;
193      int status = 0;
194    
195      pid_t child = fork();
196    
197      if (child == -1)
198        goto out;
199    
200      if (child == 0) {
201        execvp(name, argv);
202        _exit(EXIT_FAILURE);
203      }
204    
205      do {
206        result = waitpid(child, &status, 0);
207      } while (result == -1 && errno == EINTR);
208    
209      if (result == -1)
210        goto out;
211    
212      if (WIFEXITED(status))
213        result = WEXITSTATUS(status);
214    
215    out:
216      free((void *) argv);
217      return result;
218    }
219    #endif

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.4.2.6

  ViewVC Help
Powered by ViewVC 1.1.5