2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
11 #include "PortableStrlcpy.h"
13 MainArgs
*MainArgs_new(void)
15 MainArgs
*self
= (MainArgs
*)io_calloc(1, sizeof(MainArgs
));
19 void MainArgs_free(MainArgs
*self
)
25 for (i
= 0; i
< self
->argc
; i
++)
27 io_free((char *)(self
->argv
[i
]));
30 io_free((void*)(self
->argv
));
36 void MainArgs_argc_argv_(MainArgs
*self
, int argc
, const char **argv
)
41 // copy by reference since args should be retained on
42 // the C stack until the program exits
44 self
->argv
= (const char **)io_calloc(1, sizeof(char *)*argc
);
46 for (i
= 0; i
< argc
; i
++)
48 const char *s
= argv
[i
];
49 size_t len
= strlen(s
);
50 char *ptr
= (char *)io_calloc(1, len
+ 1);
51 PortableStrlcpy(ptr
, s
, len
+ 1);
54 //self->argv[i] = strcpy((char *)io_calloc(1, strlen(s)+1), s);
55 /*printf("argv[%i] = '%s'\n", i, s);*/