/[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.8 by kaz, Fri Feb 21 06:21:51 2003 UTC
# Line 2  Line 2 
2  #include <stdlib.h>  #include <stdlib.h>
3  #include <string.h>  #include <string.h>
4  #include <errno.h>  #include <errno.h>
5    #include <signal.h>
6  #include <dirent.h>  #include <dirent.h>
7  #include <unistd.h>  #include <unistd.h>
8  #include <sys/types.h>  #include <sys/types.h>
9  #include <sys/stat.h>  #include <sys/stat.h>
10    #include <sys/wait.h>
11    #ifdef __CYGWIN__
12    #include <process.h>
13    #endif
14    
15  /*  /*
16   * Null pointer test   * Null pointer test
17   */   */
18    
19  int impl_null_pointer_p(void *ptr)  int mcvs_null_pointer_p(void *ptr)
20  {  {
21    return ptr == 0;    return ptr == 0;
22  }  }
# Line 20  int impl_null_pointer_p(void *ptr) Line 25  int impl_null_pointer_p(void *ptr)
25   * <errno.h> stuff   * <errno.h> stuff
26   */   */
27    
28  int impl_get_errno(void)  int mcvs_get_errno(void)
29  {  {
30    return errno;    return errno;
31  }  }
32    
33  int impl_set_errno(int value)  int mcvs_set_errno(int value)
34  {  {
35    return errno = value;    return errno = value;
36  }  }
# Line 37  int impl_set_errno(int value) Line 42  int impl_set_errno(int value)
42  typedef struct {  typedef struct {
43    unsigned long d_ino;    unsigned long d_ino;
44    char d_name[1024];    char d_name[1024];
45  } impl_dirent;  } mcvs_dirent;
46    
47  impl_dirent *impl_readdir(DIR *dir)  mcvs_dirent *mcvs_readdir(DIR *dir)
48  {  {
49    static impl_dirent dw;    static mcvs_dirent dw;
50    struct dirent *de = readdir(dir);    struct dirent *de = readdir(dir);
51    if (de != 0) {    if (de != 0) {
52      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 60  impl_dirent *impl_readdir(DIR *dir)
60   * <unistd.h> stuff   * <unistd.h> stuff
61   */   */
62    
63  char *impl_readlink(const char *path)  char *mcvs_readlink(const char *path)
64  {  {
65    size_t size = 256;    size_t size = 256;
66    char *str = malloc(size);    char *str = malloc(size);
# Line 92  bail: Line 97  bail:
97   * <sys/stat.h> stuff   * <sys/stat.h> stuff
98   */   */
99    
100  struct impl_stat {  struct mcvs_stat {
101    unsigned long dev;    unsigned long dev;
102    unsigned long ino;    unsigned long ino;
103    unsigned long mode;    unsigned long mode;
# Line 107  struct impl_stat { Line 112  struct impl_stat {
112    unsigned long ctime;    unsigned long ctime;
113  };  };
114    
115  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)
116  {  {
117    out->dev = in->st_dev;    out->dev = in->st_dev;
118    out->ino = in->st_ino;    out->ino = in->st_ino;
# Line 124  static void stat_to_impl(struct impl_sta Line 129  static void stat_to_impl(struct impl_sta
129  }  }
130    
131  #define IMPL_STAT(FUNC, ARGTYPE) \  #define IMPL_STAT(FUNC, ARGTYPE) \
132  int impl_ ## FUNC(ARGTYPE arg, struct impl_stat *buf) \  int mcvs_ ## FUNC(ARGTYPE arg, struct mcvs_stat *buf) \
133  { \  { \
134    struct stat sbuf; \    struct stat sbuf; \
135    int retval = FUNC(arg, &sbuf); \    int retval = FUNC(arg, &sbuf); \
136    if (retval == 0) \    if (retval == 0) \
137      stat_to_impl(buf, &sbuf); \      stat_to_wrap(buf, &sbuf); \
138    return retval; \    return retval; \
139  }  }
140    
# Line 141  IMPL_STAT(fstat, int) Line 146  IMPL_STAT(fstat, int)
146   * <unistd.h> -- getcwd   * <unistd.h> -- getcwd
147   */   */
148    
149  const char *impl_getcwd(void)  const char *mcvs_getcwd(void)
150  {  {
151    size_t size = 256;    size_t size = 256;
152    char *str = malloc(size);    char *str = malloc(size);
# Line 151  const char *impl_getcwd(void) Line 156  const char *impl_getcwd(void)
156      goto bail;      goto bail;
157    
158    while (getcwd(str, size) == 0) {    while (getcwd(str, size) == 0) {
159        if (errno != ERANGE)
160          goto bail;
161      if (size * 2 < size)      if (size * 2 < size)
162        goto bail;        goto bail;
163      size *= 2;      size *= 2;
# Line 166  bail: Line 173  bail:
173    free(str);    free(str);
174    return 0;    return 0;
175  }  }
176    
177    /*
178     * We need this because CLISP sets it to SIG_IGN, which is
179     * inherited by the exec'd image, and causes the wait()
180     * functions to have behavior that programs don't expect.
181     */
182    
183    void mcvs_default_sigchld()
184    {
185        puts("in mcvs_default_sigchld");
186        signal(SIGCHLD, SIG_DFL);
187    }
188    
189    /*
190     * <unistd.h> -- fork, wait*, exec*
191     */
192    
193    #ifdef __CYGWIN__
194    /*
195     * On Cygwin, we have a straightforward alternative to fork exec
196     * and wait, so let's use it.
197     */
198    
199    int mcvs_spawn(const char *name, const char *const *argv)
200    {
201      return spawnvp(_P_WAIT, name, argv);
202    }
203    #else
204    int mcvs_spawn(const char *name, char *const *argv)
205    {
206      int result = -1;
207      int status = 0;
208    
209      pid_t child = fork();
210    
211      if (child == -1)
212        goto out;
213    
214      if (child == 0) {
215        mcvs_default_sigchld();
216        execvp(name, argv);
217        _exit(EXIT_FAILURE);
218      }
219    
220      do {
221        result = waitpid(child, &status, 0);
222      } while (result == -1 && errno == EINTR);
223    
224      if (result == -1)
225        goto out;
226    
227      if (WIFEXITED(status))
228        result = WEXITSTATUS(status);
229    
230    out:
231      free((void *) argv);
232      return result;
233    }
234    #endif

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

  ViewVC Help
Powered by ViewVC 1.1.5