Cleanup: use BLI_path_basename
authorCampbell Barton <ideasman42@gmail.com>
Tue, 6 Oct 2015 08:49:58 +0000 (19:49 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 6 Oct 2015 08:49:58 +0000 (19:49 +1100)
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/sound.c

index c314131e2464f0c9b40173ca4ce5209be5bb7d5b..c421c67d9e58f21c3994e8f83ba83f8f29a2c855 100644 (file)
@@ -704,8 +704,7 @@ void BKE_image_alpha_mode_from_extension(Image *image)
 Image *BKE_image_load(Main *bmain, const char *filepath)
 {
        Image *ima;
-       int file, len;
-       const char *libname;
+       int file;
        char str[FILE_MAX];
 
        BLI_strncpy(str, filepath, sizeof(str));
@@ -717,13 +716,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
                return NULL;
        close(file);
 
-       /* create a short library name */
-       len = strlen(filepath);
-
-       while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\') len--;
-       libname = filepath + len;
-
-       ima = image_alloc(bmain, libname, IMA_SRC_FILE, IMA_TYPE_IMAGE);
+       ima = image_alloc(bmain, BLI_path_basename(filepath), IMA_SRC_FILE, IMA_TYPE_IMAGE);
        BLI_strncpy(ima->name, filepath, sizeof(ima->name));
 
        if (BLI_testextensie_array(filepath, imb_ext_movie))
index ed92c942b57e4dfab20d804ffb88bce4b4c85982..a23e9400b828e5482e95e7c800ba813b6348983f 100644 (file)
@@ -603,8 +603,7 @@ static void detect_clip_source(MovieClip *clip)
 MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
 {
        MovieClip *clip;
-       int file, len;
-       const char *libname;
+       int file;
        char str[FILE_MAX];
 
        BLI_strncpy(str, name, sizeof(str));
@@ -619,13 +618,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
        /* ** add new movieclip ** */
 
        /* create a short library name */
-       len = strlen(name);
-
-       while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\')
-               len--;
-       libname = name + len;
-
-       clip = movieclip_alloc(bmain, libname);
+       clip = movieclip_alloc(bmain, BLI_path_basename(name));
        BLI_strncpy(clip->name, name, sizeof(clip->name));
 
        detect_clip_source(clip);
index a800d8f3f381483edbff8374b15c145c1815056b..7e7cc8745fde1a7465a1d3ebf0e64ef2eeab9b8e 100644 (file)
@@ -74,11 +74,8 @@ static char **audio_device_names = NULL;
 bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath)
 {
        bSound *sound;
-
-       char str[FILE_MAX];
        const char *path;
-
-       size_t len;
+       char str[FILE_MAX];
 
        BLI_strncpy(str, filepath, sizeof(str));
 
@@ -86,11 +83,7 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath)
 
        BLI_path_abs(str, path);
 
-       len = strlen(filepath);
-       while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\')
-               len--;
-
-       sound = BKE_libblock_alloc(bmain, ID_SO, filepath + len);
+       sound = BKE_libblock_alloc(bmain, ID_SO, BLI_path_basename(filepath));
        BLI_strncpy(sound->name, filepath, FILE_MAX);
        /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */