Mercurial > sdl-ios-xcode
comparison src/video/riscos/SDL_riscostask.c @ 1379:c0a74f199ecf
Use only safe string functions
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Feb 2006 23:46:34 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
comparison
equal
deleted
inserted
replaced
1378:dc0e13e7e1ae | 1379:c0a74f199ecf |
---|---|
55 | 55 |
56 extern int mouseInWindow; /* Mouse is in WIMP window */ | 56 extern int mouseInWindow; /* Mouse is in WIMP window */ |
57 | 57 |
58 /* Local function */ | 58 /* Local function */ |
59 | 59 |
60 static int RISCOS_GetTaskName(char *task_name); | 60 static int RISCOS_GetTaskName(char *task_name, size_t maxlen); |
61 | 61 |
62 /* Uncomment next line to copy mode changes/restores to stderr */ | 62 /* Uncomment next line to copy mode changes/restores to stderr */ |
63 /* #define DUMP_MODE */ | 63 /* #define DUMP_MODE */ |
64 #ifdef DUMP_MODE | 64 #ifdef DUMP_MODE |
65 #include "stdio.h" | 65 #include "stdio.h" |
89 { | 89 { |
90 char task_name[32]; | 90 char task_name[32]; |
91 _kernel_swi_regs regs; | 91 _kernel_swi_regs regs; |
92 int messages[4]; | 92 int messages[4]; |
93 | 93 |
94 if (RISCOS_GetTaskName(task_name) == 0) return 0; | 94 if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0) return 0; |
95 | 95 |
96 messages[0] = 9; /* Palette changed */ | 96 messages[0] = 9; /* Palette changed */ |
97 messages[1] = 0x400c1; /* Mode changed */ | 97 messages[1] = 0x400c1; /* Mode changed */ |
98 messages[2] = 8; /* Pre quit */ | 98 messages[2] = 8; /* Pre quit */ |
99 messages[2] = 0; | 99 messages[2] = 0; |
175 0 Don't show close icon | 175 0 Don't show close icon |
176 1 Show close icon | 176 1 Show close icon |
177 | 177 |
178 ***************************************************************************/ | 178 ***************************************************************************/ |
179 | 179 |
180 int RISCOS_GetTaskName(char *task_name) | 180 int RISCOS_GetTaskName(char *task_name, size_t maxlen) |
181 { | 181 { |
182 _kernel_swi_regs regs; | 182 _kernel_swi_regs regs; |
183 | 183 |
184 task_name[0] = 0; | 184 task_name[0] = 0; |
185 | 185 |
186 /* Figure out a sensible task name */ | 186 /* Figure out a sensible task name */ |
187 if (_kernel_swi(OS_GetEnv, ®s, ®s) == 0) | 187 if (_kernel_swi(OS_GetEnv, ®s, ®s) == 0) |
188 { | 188 { |
189 char *command_line = (char *)regs.r[0]; | 189 char *command_line = (char *)regs.r[0]; |
190 char *buffer = SDL_malloc(SDL_strlen(command_line)+1); | 190 size_t len = SDL_strlen(command_line)+1; |
191 char *buffer = SDL_stack_alloc(char, len); | |
191 char *env_var; | 192 char *env_var; |
192 char *p; | 193 char *p; |
193 | 194 |
194 SDL_strcpy(buffer, command_line); | 195 SDL_strlcpy(buffer, command_line, len); |
195 p = SDL_strchr(buffer, ' '); | 196 p = SDL_strchr(buffer, ' '); |
196 if (p) *p = 0; | 197 if (p) *p = 0; |
197 p = SDL_strrchr(buffer, '.'); | 198 p = SDL_strrchr(buffer, '.'); |
198 if (p == 0) p = buffer; | 199 if (p == 0) p = buffer; |
199 if (stricmp(p+1,"!RunImage") == 0) | 200 if (stricmp(p+1,"!RunImage") == 0) |
215 } | 216 } |
216 | 217 |
217 if (*p) | 218 if (*p) |
218 { | 219 { |
219 /* Read variables that effect the RISC OS SDL engine for this task */ | 220 /* Read variables that effect the RISC OS SDL engine for this task */ |
220 env_var = SDL_malloc(SDL_strlen(p) + 18); /* 18 is larger than the biggest variable name */ | 221 len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */ |
222 env_var = SDL_stack_alloc(char, len); | |
221 if (env_var) | 223 if (env_var) |
222 { | 224 { |
223 char *env_val; | 225 char *env_val; |
224 | 226 |
225 /* See if a variable of form SDL$<dirname>$TaskName exists */ | 227 /* See if a variable of form SDL$<dirname>$TaskName exists */ |
226 | 228 |
227 SDL_strcpy(env_var, "SDL$"); | 229 SDL_strlcpy(env_var, "SDL$", len); |
228 strcat(env_var, p); | 230 SDL_strlcat(env_var, p, len); |
229 strcat(env_var, "$TaskName"); | 231 SDL_strlcat(env_var, "$TaskName", len); |
230 | 232 |
231 env_val = SDL_getenv(env_var); | 233 env_val = SDL_getenv(env_var); |
232 if (env_val) SDL_strncpy(task_name, env_val, 31); | 234 if (env_val) SDL_strlcpy(task_name, env_val, maxlen); |
233 | 235 |
234 SDL_strcpy(env_var, "SDL$"); | 236 SDL_strlcpy(env_var, "SDL$", len); |
235 strcat(env_var, p); | 237 SDL_strlcat(env_var, p, len); |
236 strcat(env_var, "$BackBuffer"); | 238 SDL_strlcat(env_var, "$BackBuffer", len); |
237 | 239 |
238 env_val = SDL_getenv(env_var); | 240 env_val = SDL_getenv(env_var); |
239 if (env_val) riscos_backbuffer = atoi(env_val); | 241 if (env_val) riscos_backbuffer = atoi(env_val); |
240 | 242 |
241 SDL_strcpy(env_var, "SDL$"); | 243 SDL_strlcpy(env_var, "SDL$", len); |
242 strcat(env_var, p); | 244 SDL_strlcat(env_var, p, len); |
243 strcat(env_var, "$CloseAction"); | 245 SDL_strlcat(env_var, "$CloseAction", len); |
244 | 246 |
245 env_val = SDL_getenv(env_var); | 247 env_val = SDL_getenv(env_var); |
246 if (env_val && SDL_strcmp(env_val,"0") == 0) riscos_closeaction = 0; | 248 if (env_val && SDL_strcmp(env_val,"0") == 0) riscos_closeaction = 0; |
247 | 249 |
248 SDL_free(env_var); | 250 SDL_stack_free(env_var); |
249 } | 251 } |
250 | 252 |
251 if (task_name[0] == 0) SDL_strncpy(task_name, p, 31); | 253 if (!*task_name) SDL_strlcpy(task_name, p, maxlen); |
252 task_name[31] = 0; | |
253 } | 254 } |
254 | 255 |
255 SDL_free(buffer); | 256 SDL_stack_free(buffer); |
256 } | 257 } |
257 | 258 |
258 if (task_name[0] == 0) SDL_strcpy(task_name, "SDL Task"); | 259 if (task_name[0] == 0) SDL_strlcpy(task_name, "SDL Task", maxlen); |
259 | 260 |
260 return 1; | 261 return 1; |
261 } | 262 } |
262 | 263 |
263 /***************************************************************** | 264 /***************************************************************** |