Code

Imported ncmpc (mpc-ncures).
[ncmpc.git] / support.c
1 /*
2  * $Id: support.c,v 1.2 2004/03/17 23:17:09 kalle Exp $
3  *
4  */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <glib.h>
11 #include "config.h"
12 #include "support.h"
14 #ifndef HAVE_LIBGEN_H
16 char *
17 remove_trailing_slash(char *path)
18 {
19   int len;
21   if( path==NULL )
22     return NULL;
24   len=strlen(path);
25   if( len>1 && path[len-1] == '/' )
26     path[len-1] = '\0';
28   return path;
29 }
32 char *
33 basename(char *path)
34 {
35   char *end;
37   path = remove_trailing_slash(path);
38   end = path + strlen(path);
40   while( end>path && *end!='/' )
41     end--;
43   if( *end=='/' && end!=path )
44     return end+1;
46   return path;
47 }
49 #endif /* HAVE_LIBGEN_H */
51 char *
52 utf8(char *str)
53 {
54   static const gchar *charset = NULL;
55   static gboolean locale_is_utf8 = FALSE;
57   if( !charset )
58     locale_is_utf8 = g_get_charset(&charset);
60   if( locale_is_utf8 )
61     return str;
63   return g_locale_from_utf8(str, -1, NULL, NULL, NULL);
64 }