1
|
/*
|
2
|
This source file is part of Scol
|
3
|
For the latest info, see http://www.scolring.org
|
4
|
|
5
|
Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>
|
6
|
|
7
|
This program is free software; you can redistribute it and/or modify it under
|
8
|
the terms of the GNU Lesser General Public License as published by the Free Software
|
9
|
Foundation; either version 2 of the License, or (at your option) any later
|
10
|
version.
|
11
|
|
12
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
13
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
15
|
|
16
|
You should have received a copy of the GNU Lesser General Public License along with
|
17
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
18
|
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
19
|
http://www.gnu.org/copyleft/lesser.txt
|
20
|
|
21
|
For others informations, please contact us from http://www.scolring.org/
|
22
|
*/
|
23
|
|
24
|
|
25
|
#include "../include/scol_glib_misc.h"
|
26
|
|
27
|
|
28
|
/**
|
29
|
* \brief Returns the name of the executable Scol. The filename should NOT be freed
|
30
|
* It should return "scol.exe" (or "unsmwin.exe" on the old Scol version) on MS Windows
|
31
|
* On GNU/ Linux, it should return "scol" or "usmunix"
|
32
|
* \return gchar * : this filename
|
33
|
*/
|
34
|
const gchar * scol_glib_name_scolexe ()
|
35
|
{
|
36
|
return g_get_application_name ();
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* \brief Returns the filename of the current Scol. The filename should be freed with g_free
|
41
|
* \return gchar * : this filename
|
42
|
*/
|
43
|
gchar * scol_glib_filename_scol ()
|
44
|
{
|
45
|
return g_find_program_in_path (scol_glib_name_scolexe ());
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* \brief Returns the directory of the current Scol. The filename should be freed with g_free
|
50
|
* \return gchar * : this filename
|
51
|
*/
|
52
|
gchar * scol_glib_dirname_scol ()
|
53
|
{
|
54
|
gchar * f = scol_glib_filename_scol ();
|
55
|
gchar * p;
|
56
|
|
57
|
p = g_path_get_dirname (f);
|
58
|
g_free (f);
|
59
|
return p;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* \brief Returns the basename of any filename. The result should be freed with g_free
|
64
|
* \param : const gchar * : any filename
|
65
|
* \return gchar * : this base name
|
66
|
*/
|
67
|
gchar * scol_glib_basename (const gchar *f)
|
68
|
{
|
69
|
return g_path_get_basename (f);
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* \brief Returns the value of any environment variable or NULL if not found
|
74
|
* \param const gchar * : an environment variable, without "$" on Linux and without "%" on Windows
|
75
|
* \return const gchar * : the value or NULL if not ound
|
76
|
* This is an alias of g_getenv ()
|
77
|
* The result should not be freed
|
78
|
*/
|
79
|
const gchar * scol_glib_get_env (const gchar *v)
|
80
|
{
|
81
|
return g_getenv (v);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* \brief Returns the name ofthe current user
|
86
|
* \return const gchar * : the name
|
87
|
* This is an alias of g_get_user_name ()
|
88
|
*/
|
89
|
const gchar * scol_glib_get_username ()
|
90
|
{
|
91
|
return g_get_user_name ();
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* \brief Returns the host name. Don't free !
|
96
|
* \return const gchar * : the result.
|
97
|
*/
|
98
|
const gchar * scol_glib_get_hostname ()
|
99
|
{
|
100
|
return g_get_host_name ();
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* \brief Returns TRUE if the given path is an absolute path, otherwise FALSE
|
105
|
* \param const gchar * : any path
|
106
|
* \return gboolean
|
107
|
*/
|
108
|
gboolean scol_glib_isabsolutepath (const gchar * p)
|
109
|
{
|
110
|
return g_path_is_absolute (p);
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* \brief Returns a string with an easy sizenumber (from bytes to KB, MO, ..)
|
115
|
* \param int : an integer (by example a Scol value)
|
116
|
* \return char *
|
117
|
* The result should be freed with g_free
|
118
|
*/
|
119
|
char * scol_glib_get_sizefordisplay (int v)
|
120
|
{
|
121
|
return g_format_size_for_display ((goffset) v);
|
122
|
}
|
123
|
|
124
|
|
125
|
|