]> icculus.org git repositories - taylor/freespace2.git/blob - src/freespace2/main.cpp
use umask() on *nix for better permissions
[taylor/freespace2.git] / src / freespace2 / main.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 #include "pstypes.h"
10
11 #ifdef PLAT_UNIX
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #endif
15
16 #undef malloc
17 #undef free
18
19 extern int game_main(const char *szCmdLine);
20
21 void vm_dump();
22
23
24 int main(int argc, char **argv)
25 {
26         char *argptr = NULL;
27         int i;
28         int len = 0;
29         int retr = 0;
30
31 #ifdef PLAT_UNIX
32         // make sure we create files with user access only
33         umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
34 #endif
35
36         for (i = 1; i < argc; i++) {
37                 len += strlen(argv[i]) + 1;
38         }
39
40         if (len > 0) {
41                 argptr = (char *)malloc(len+5);
42
43                 if (argptr == NULL) {
44                         SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Ran out of memory in main()!", NULL);
45                         exit(1);
46                 }
47
48                 memset(argptr, 0, len+5);
49
50                 for (i = 1; i < argc; i++) {
51                         strcat(argptr, argv[i]);
52                         strcat(argptr, " ");
53                 }
54         }
55
56         try {
57                 retr = game_main(argptr);
58         } catch(...) {
59                 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Exception caught in main()!", NULL);
60         }
61
62         if (argptr) {
63                 free(argptr);
64         }
65                 
66         vm_dump();
67         
68         return retr;    
69 }