-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_utils.c
94 lines (69 loc) · 2 KB
/
path_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
FTP file system
Copyright (C) 2007 Robson Braga Araujo <robsonbraga@gmail.com>
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
*/
#include "path_utils.h"
#include "charset_utils.h"
#include "ftpfs.h"
#include <string.h>
#include <stdlib.h>
#include <glib.h>
char* get_file_name(const char* path) {
const char* filename = strrchr(path, '/');
if (filename == NULL) filename = path;
else ++filename;
char* ret = strdup(filename);
if (ftpfs.codepage) {
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &ret);
}
return ret;
}
char* get_full_path(const char* path) {
char* ret;
char* converted_path = NULL;
++path;
if (ftpfs.codepage && strlen(path)) {
converted_path = strdup(path);
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &converted_path);
path = converted_path;
}
ret = g_strdup_printf("%s%s", ftpfs.host, path);
free(converted_path);
return ret;
}
char* get_fulldir_path(const char* path) {
char* ret;
char* converted_path = NULL;
++path;
if (ftpfs.codepage && strlen(path)) {
converted_path = strdup(path);
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &converted_path);
path = converted_path;
}
ret = g_strdup_printf("%s%s%s", ftpfs.host, path, strlen(path) ? "/" : "");
free(converted_path);
return ret;
}
char* get_dir_path(const char* path) {
char* ret;
char* converted_path = NULL;
const char *lastdir;
++path;
lastdir = strrchr(path, '/');
if (lastdir == NULL) lastdir = path;
if (ftpfs.codepage && (lastdir - path > 0)) {
converted_path = g_strndup(path, lastdir - path);
convert_charsets(ftpfs.iocharset, ftpfs.codepage, &converted_path);
path = converted_path;
lastdir = path + strlen(path);
}
ret = g_strdup_printf("%s%.*s%s",
ftpfs.host,
lastdir - path,
path,
lastdir - path ? "/" : "");
free(converted_path);
return ret;
}