2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/string.h>
8 extern char **_environ;
18 char* strndup(char* name, int len)
20 char *s = malloc(len + 1);
23 strncpy(s, name, len);
28 #define SIZE (4096 / sizeof(char*))
33 if ((__argc % SIZE) == 0)
35 _new = malloc(sizeof(char*) * (__argc + SIZE));
42 memcpy(_new, __argv, sizeof(char*) * __argc);
47 __argv[__argc++] = name;
50 int expand(char* name)
59 s = strpbrk(name, "*?");
62 hFile = FindFirstFile(name, &fd);
63 if (hFile != INVALID_HANDLE_VALUE)
65 while(s != name && *s != '/' && *s != '\\')
68 if (*s == '/' || *s == '\\')
70 strncpy(buffer, name, pos);
73 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
75 strcpy(&buffer[pos], fd.cFileName);
76 if (add(strdup(buffer)) < 0)
84 while(FindNextFile(hFile, &fd));
98 int __getmainargs(int *argc,char ***argv,char ***env,int flag)
100 int i,afterlastspace;
102 /* missing threading init */
111 expand(strndup(_acmdln + afterlastspace, i - afterlastspace));
113 while (_acmdln[i]==' ')
123 if (_acmdln[afterlastspace] != 0)
125 expand(strndup(_acmdln+afterlastspace, i - afterlastspace));
128 HeapValidate(hHeap,0,NULL);
134 _pgmptr = strdup((char *)argv[0]);
140 int *__p___argc(void)
145 char ***__p___argv(void)