Sample: cleaning up Inheritance
[io/quag.git] / libs / basekit / source / MainArgs.c
blobc355688656cd91d11f7a0eeda80ebd0409d91045
1 /*#io
2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
4 */
6 #include "Base.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "MainArgs.h"
11 #include "PortableStrlcpy.h"
13 MainArgs *MainArgs_new(void)
15 MainArgs *self = (MainArgs *)io_calloc(1, sizeof(MainArgs));
16 return self;
19 void MainArgs_free(MainArgs *self)
21 if (self->argv)
23 int i;
25 for (i = 0; i < self->argc; i ++)
27 io_free((char *)(self->argv[i]));
30 io_free((void*)(self->argv));
33 io_free(self);
36 void MainArgs_argc_argv_(MainArgs *self, int argc, const char **argv)
38 int i;
40 self->argc = argc;
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);
52 self->argv[i] = ptr;
54 //self->argv[i] = strcpy((char *)io_calloc(1, strlen(s)+1), s);
55 /*printf("argv[%i] = '%s'\n", i, s);*/