2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/string.h>
19 char* strndup(char* name, int len)
21 char *s = malloc(len + 1);
23 strncpy(s, name, len);
28 #define SIZE (4096 / sizeof(char*))
33 if ((__argc % SIZE) == 0) {
34 _new = malloc(sizeof(char*) * (__argc + SIZE));
39 memcpy(_new, __argv, sizeof(char*) * __argc);
44 __argv[__argc++] = name;
48 int expand(char* name)
57 s = strpbrk(name, "*?");
59 hFile = FindFirstFile(name, &fd);
60 if (hFile != INVALID_HANDLE_VALUE) {
61 while(s != name && *s != '/' && *s != '\\')
64 if (*s == '/' || *s == '\\')
66 strncpy(buffer, name, pos);
68 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
69 strcpy(&buffer[pos], fd.cFileName);
70 if (add(strdup(buffer)) < 0) {
77 while(FindNextFile(hFile, &fd));
90 int __getmainargs(int* argc, char*** argv, char*** env, int flag)
92 int i, afterlastspace;
94 /* missing threading init */
100 if (_acmdln[i] == ' ') {
101 expand(strndup(_acmdln + afterlastspace, i - afterlastspace));
103 while (_acmdln[i]==' ')
111 if (_acmdln[afterlastspace] != 0) {
112 expand(strndup(_acmdln+afterlastspace, i - afterlastspace));
114 HeapValidate(hHeap, 0, NULL);
118 _pgmptr = strdup((char*)argv[0]);
122 int* __p___argc(void)
127 char*** __p___argv(void)