libvisual
0.5.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
libvisual
lv_util.c
1
#include "lv_util.h"
2
#include "lv_common.h"
3
#include <string.h>
4
5
char
*visual_strdup (
const
char
*str)
6
{
7
size_t
size = strlen (str) + 1;
8
char
*new_str =
visual_mem_malloc
(size);
9
10
return
(
char
*) memcpy (new_str, str, size);
11
}
12
13
const
char
*visual_truncate_path (
const
char
* filename,
unsigned
int
parts)
14
{
15
/* Start looking for '/' from the end of the filename */
16
const
char
*s = filename + strlen (filename);
17
18
unsigned
int
i;
19
20
for
(i = 0; i < parts; i++) {
21
/* Scan backwards until we hit '/' or the beginning of the string */
22
while
(s != filename && *s !=
'/'
)
23
s--;
24
25
/* If we hit the beginning, we just return the filename, unmodified */
26
if
(s == filename)
27
return
filename;
28
29
/* Skip this instance of / */
30
s--;
31
}
32
33
/* We found the final /. Return the substring that begins right after it */
34
return
s + 2;
35
}