use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender.git] / source / blender / editors / space_file / filelist.c
index b478976..32fe849 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -48,7 +46,6 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
-#include "BLI_storage_types.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
@@ -377,7 +374,7 @@ void filelist_init_icons(void)
 #ifdef WITH_HEADLESS
        bbuf = NULL;
 #else
-       bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_prvicons, datatoc_prvicons_size, IB_rect);
+       bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_prvicons, datatoc_prvicons_size, IB_rect, "<splash>");
 #endif
        if (bbuf) {
                for (y=0; y<SPECIAL_IMG_ROWS; y++) {
@@ -669,7 +666,7 @@ struct direntry * filelist_file(struct FileList* filelist, int index)
        return &filelist->filelist[fidx];
 }
 
-int filelist_find(struct FileList* filelist, char *file)
+int filelist_find(struct FileList* filelist, const char *filename)
 {
        int index = -1;
        int i;
@@ -680,7 +677,7 @@ int filelist_find(struct FileList* filelist, char *file)
 
        
        for (i = 0; i < filelist->numfiles; ++i) {
-               if ( strcmp(filelist->filelist[i].relname, file) == 0) { /* not dealing with user input so dont need BLI_path_cmp */
+               if ( strcmp(filelist->filelist[i].relname, filename) == 0) { /* not dealing with user input so dont need BLI_path_cmp */
                        index = i;
                        break;
                }
@@ -825,10 +822,10 @@ static void filelist_read_dir(struct FileList* filelist)
        filelist->fidx = NULL;
        filelist->filelist = NULL;
 
-       BLI_getwdN(wdir, sizeof(wdir));  /* backup cwd to restore after */
+       BLI_current_working_dir(wdir, sizeof(wdir));     /* backup cwd to restore after */
 
        BLI_cleanup_dir(G.main->name, filelist->dir);
-       filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));
+       filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist));
 
        if(!chdir(wdir)) {} /* fix warning about not checking return value */
        filelist_setfiletypes(filelist);
@@ -855,7 +852,7 @@ static void filelist_read_library(struct FileList* filelist)
                file = filelist->filelist;
                for(num=0; num<filelist->numfiles; num++, file++) {
                        if(BLO_has_bfile_extension(file->relname)) {
-                               char name[FILE_MAXDIR+FILE_MAXFILE];
+                               char name[FILE_MAX];
                        
                                BLI_strncpy(name, filelist->dir, sizeof(name));
                                strcat(name, file->relname);
@@ -973,7 +970,7 @@ int filelist_islibrary(struct FileList* filelist, char* dir, char* group)
        return BLO_is_a_library(filelist->dir, dir, group);
 }
 
-static int groupname_to_code(char *group)
+static int groupname_to_code(const char *group)
 {
        char buf[32];
        char *lslash;
@@ -991,7 +988,7 @@ void filelist_from_library(struct FileList* filelist)
        LinkNode *l, *names, *previews;
        struct ImBuf* ima;
        int ok, i, nprevs, nnames, idcode;
-       char filename[FILE_MAXDIR+FILE_MAXFILE];
+       char filename[FILE_MAX];
        char dir[FILE_MAX], group[GROUP_MAX];   
        
        /* name test */
@@ -1182,7 +1179,7 @@ void filelist_from_main(struct FileList *filelist)
                                        if(id->lib==NULL)
                                                files->relname= BLI_strdup(id->name+2);
                                        else {
-                                               files->relname= MEM_mallocN(FILE_MAXDIR+FILE_MAXFILE+32, "filename for lib");
+                                               files->relname= MEM_mallocN(FILE_MAX+32, "filename for lib");
                                                sprintf(files->relname, "%s | %s", id->lib->name, id->name+2);
                                        }
                                        files->type |= S_IFREG;
@@ -1202,10 +1199,10 @@ void filelist_from_main(struct FileList *filelist)
                                        if(idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) {
                                                files->flags |= IMAGEFILE;
                                        }
-                                       if(id->lib && fake) sprintf(files->extra, "LF %d", id->us);
-                                       else if(id->lib) sprintf(files->extra, "L    %d", id->us);
-                                       else if(fake) sprintf(files->extra, "F    %d", id->us);
-                                       else sprintf(files->extra, "      %d", id->us);
+                                       if(id->lib && fake) BLI_snprintf(files->extra, sizeof(files->extra), "LF %d", id->us);
+                                       else if(id->lib) BLI_snprintf(files->extra, sizeof(files->extra), "L    %d", id->us);
+                                       else if(fake) BLI_snprintf(files->extra, sizeof(files->extra), "F    %d", id->us);
+                                       else BLI_snprintf(files->extra, sizeof(files->extra), "      %d", id->us);
                                        
                                        if(id->lib) {
                                                if(totlib==0) firstlib= files;