comparison src/cdrom/aix/SDL_syscdrom.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
122 } 122 }
123 } 123 }
124 124
125 /* Add this drive to our list */ 125 /* Add this drive to our list */
126 i = SDL_numcds; 126 i = SDL_numcds;
127 SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); 127 SDL_cdlist[i] = SDL_strdup(drive);
128 if ( SDL_cdlist[i] == NULL ) { 128 if ( SDL_cdlist[i] == NULL ) {
129 SDL_OutOfMemory(); 129 SDL_OutOfMemory();
130 return; 130 return;
131 } 131 }
132 SDL_strcpy(SDL_cdlist[i], drive);
133 SDL_cdmode[i] = stbuf->st_rdev; 132 SDL_cdmode[i] = stbuf->st_rdev;
134 ++SDL_numcds; 133 ++SDL_numcds;
135 #ifdef DEBUG_CDROM 134 #ifdef DEBUG_CDROM
136 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 135 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
137 #endif 136 #endif
300 299
301 /* Look in the environment for our CD-ROM drive list */ 300 /* Look in the environment for our CD-ROM drive list */
302 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 301 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
303 if ( SDLcdrom != NULL ) { 302 if ( SDLcdrom != NULL ) {
304 char *cdpath, *delim; 303 char *cdpath, *delim;
305 cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); 304 size_t len = SDL_strlen(SDLcdrom)+1;
305 cdpath = SDL_stack_alloc(char, len);
306 if ( cdpath != NULL ) { 306 if ( cdpath != NULL ) {
307 SDL_strcpy(cdpath, SDLcdrom); 307 SDL_strlcpy(cdpath, SDLcdrom, len);
308 SDLcdrom = cdpath; 308 SDLcdrom = cdpath;
309 do { 309 do {
310 delim = SDL_strchr(SDLcdrom, ':'); 310 delim = SDL_strchr(SDLcdrom, ':');
311 if ( delim ) { 311 if ( delim ) {
312 *delim++ = '\0'; 312 *delim++ = '\0';
321 SDLcdrom = delim; 321 SDLcdrom = delim;
322 } else { 322 } else {
323 SDLcdrom = NULL; 323 SDLcdrom = NULL;
324 } 324 }
325 } while ( SDLcdrom ); 325 } while ( SDLcdrom );
326 SDL_free(cdpath); 326 SDL_stack_free(cdpath);
327 } 327 }
328 328
329 /* If we found our drives, there's nothing left to do */ 329 /* If we found our drives, there's nothing left to do */
330 if ( SDL_numcds > 0 ) { 330 if ( SDL_numcds > 0 ) {
331 return(0); 331 return(0);
358 static int SDL_SYS_CDOpen(int drive) 358 static int SDL_SYS_CDOpen(int drive)
359 { 359 {
360 int fd; 360 int fd;
361 char* lastsl; 361 char* lastsl;
362 char* cdromname; 362 char* cdromname;
363 size_t len;
363 364
364 /* 365 /*
365 * We found /dev/cd? drives and that is in our list. But we can 366 * We found /dev/cd? drives and that is in our list. But we can
366 * open only the /dev/rcd? versions of those devices for Audio CD. 367 * open only the /dev/rcd? versions of those devices for Audio CD.
367 */ 368 */
368 cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) ); 369 len = SDL_strlen(SDL_cdlist[drive])+2;
369 SDL_strcpy(cdromname,SDL_cdlist[drive]); 370 cdromname = (char*)SDL_malloc(len);
371 SDL_strlcpy(cdromname,SDL_cdlist[drive],len);
370 lastsl = SDL_strrchr(cdromname,'/'); 372 lastsl = SDL_strrchr(cdromname,'/');
371 if (lastsl) { 373 if (lastsl) {
372 *lastsl = 0; 374 *lastsl = 0;
373 strcat(cdromname,"/r"); 375 SDL_strlcat(cdromname,"/r",len);
374 lastsl = SDL_strrchr(SDL_cdlist[drive],'/'); 376 lastsl = SDL_strrchr(SDL_cdlist[drive],'/');
375 if (lastsl) { 377 if (lastsl) {
376 lastsl++; 378 lastsl++;
377 strcat(cdromname,lastsl); 379 SDL_strlcat(cdromname,lastsl,len);
378 } 380 }
379 } 381 }
380 382
381 #ifdef DEBUG_CDROM 383 #ifdef DEBUG_CDROM
382 fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname); 384 fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname);