diff options
Diffstat (limited to 'apps/plugins/md5sum.c')
-rw-r--r-- | apps/plugins/md5sum.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/apps/plugins/md5sum.c b/apps/plugins/md5sum.c index f69c71a49f..b929d8f061 100644 --- a/apps/plugins/md5sum.c +++ b/apps/plugins/md5sum.c | |||
@@ -181,14 +181,46 @@ static void hash_check( int out, const char *path ) | |||
181 | rb->close( list ); | 181 | rb->close( list ); |
182 | } | 182 | } |
183 | 183 | ||
184 | /* | ||
185 | * Return the last name from a pathname (ignoring a trailing slash if | ||
186 | * it exists). The returned pointer points to a statically allocated | ||
187 | * buffer. | ||
188 | */ | ||
189 | static char *get_basename(const char *path) { | ||
190 | static char temp[MAX_PATH]; | ||
191 | char *p; | ||
192 | int len, isdir = 0; | ||
193 | |||
194 | rb->strcpy(temp, path); | ||
195 | |||
196 | len = rb->strlen(temp); | ||
197 | |||
198 | if (temp[len - 1] == '/') | ||
199 | { | ||
200 | /* strip trailing slash, and update length accordingly */ | ||
201 | temp[--len] = '\0'; | ||
202 | isdir = 1; | ||
203 | } | ||
204 | |||
205 | /* find the last slash, if there is one */ | ||
206 | p = rb->strrchr(temp, '/'); | ||
207 | |||
208 | /* | ||
209 | * re-append trailing slash if we previously removed it (the | ||
210 | * original NUL is still present) | ||
211 | */ | ||
212 | if(isdir) | ||
213 | temp[len++] = '/'; | ||
214 | |||
215 | return p ? (p + 1) : temp; | ||
216 | } | ||
217 | |||
184 | enum plugin_status plugin_start(const void* parameter) | 218 | enum plugin_status plugin_start(const void* parameter) |
185 | { | 219 | { |
186 | const char *arg = (const char *)parameter; /* input file path, if any */ | 220 | const char *arg = (const char *)parameter; /* input file path, if any */ |
187 | char temp[MAX_PATH]; /* input file name */ | 221 | char *basename; |
188 | char *basename=temp; | ||
189 | int out = -1; /* output file descriptor */ | 222 | int out = -1; /* output file descriptor */ |
190 | char filename[MAX_PATH]; /* output file name */ | 223 | char filename[MAX_PATH]; /* output file name */ |
191 | int isdir=0; /*flag if input file is a directory */ | ||
192 | 224 | ||
193 | void (*action)( int, const char * ) = NULL; | 225 | void (*action)( int, const char * ) = NULL; |
194 | 226 | ||
@@ -243,17 +275,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
243 | action = hash_dir; | 275 | action = hash_dir; |
244 | arg = "/"; | 276 | arg = "/"; |
245 | } | 277 | } |
246 | rb->strcpy(temp, arg); | ||
247 | if (temp[(rb->strlen(temp) - 1)] == '/') | ||
248 | { | ||
249 | temp[(rb->strlen(temp) - 1)] = '\0'; | ||
250 | isdir=1; | ||
251 | } | ||
252 | if(rb->strrchr(temp, '/')) | ||
253 | basename =(rb->strrchr(temp, '/')+1); | ||
254 | 278 | ||
255 | if(isdir) | 279 | basename = get_basename(arg); |
256 | temp[(rb->strlen(temp))] = '/'; | ||
257 | 280 | ||
258 | rb->lcd_putsf( 0, 1, "Hashing %s", basename ); | 281 | rb->lcd_putsf( 0, 1, "Hashing %s", basename ); |
259 | rb->lcd_puts( 0, 2, rb->str(LANG_ACTION_STD_CANCEL) ); | 282 | rb->lcd_puts( 0, 2, rb->str(LANG_ACTION_STD_CANCEL) ); |