File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed
Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 77#define LIBACQUIRE_ACQUIRE_NET_COMMON_H
88
99#ifdef __cplusplus
10- }
10+ extern "C" {
1111#endif /* __cplusplus */
1212
1313#include "acquire_download.h"
Original file line number Diff line number Diff line change @@ -28,20 +28,27 @@ extern LIBACQUIRE_LIB_EXPORT bool is_url(const char *);
2828#ifdef LIBACQUIRE_IMPLEMENTATION
2929
3030const char * get_path_from_url (const char * url ) {
31+ static char buf [NAME_MAX + 1 ];
32+ const char * last_slash ;
3133 size_t i ;
32- char * end_possible_query ;
33- if (url [0 ] == '\0' )
34+
35+ if (! url || url [0 ] == '\0' )
3436 return NULL ;
35- end_possible_query = strdup (url );
36- end_possible_query = strrchr (end_possible_query , '/' ) + 1 ;
37- if (end_possible_query == NULL )
38- return end_possible_query ;
39- for (i = 0 ; i < strlen (end_possible_query ); i ++ )
40- if (end_possible_query [i ] == '?' || end_possible_query [i ] == '#' ) {
41- end_possible_query [i ] = '\0' ;
37+
38+ last_slash = strrchr (url , '/' );
39+ if (last_slash )
40+ last_slash ++ ;
41+ else
42+ last_slash = url ;
43+
44+ for (i = 0 ; i < NAME_MAX && last_slash [i ] != '\0' ; i ++ ) {
45+ if (last_slash [i ] == '?' || last_slash [i ] == '#' )
4246 break ;
43- }
44- return end_possible_query ;
47+ buf [i ] = last_slash [i ];
48+ }
49+ buf [i ] = '\0' ;
50+
51+ return buf ;
4552}
4653
4754bool is_url (const char * maybe_url ) {
You can’t perform that action at this time.
0 commit comments