Some cleanups

svn path=/trunk/; revision=7817
This commit is contained in:
Matthias Clasen
2009-01-19 06:09:11 +00:00
parent 8e3622114b
commit b77a6eeac9
2 changed files with 124 additions and 108 deletions

View File

@@ -1,3 +1,7 @@
2009-01-19 Matthias Clasen <mclasen@redhat.com>
* gunixmounts.c: Some stylistic fixes.
2009-01-08 Matthias Clasen <mclasen@redhat.com> 2009-01-08 Matthias Clasen <mclasen@redhat.com>
Bug 565484 g_content_type_guess passes non-UTF8 text to XDG Bug 565484 g_content_type_guess passes non-UTF8 text to XDG

View File

@@ -335,7 +335,7 @@ G_LOCK_DEFINE_STATIC(getmntent);
#endif #endif
static GList * static GList *
_g_get_unix_mounts () _g_get_unix_mounts (void)
{ {
#ifdef HAVE_GETMNTENT_R #ifdef HAVE_GETMNTENT_R
struct mntent ent; struct mntent ent;
@@ -550,7 +550,6 @@ _g_get_unix_mounts (void)
vmount_number--; vmount_number--;
} }
g_free (vmount_info); g_free (vmount_info);
return g_list_reverse (return_list); return g_list_reverse (return_list);
@@ -746,7 +745,6 @@ _g_get_unix_mount_points (void)
) )
mount_entry->is_user_mountable = TRUE; mount_entry->is_user_mountable = TRUE;
return_list = g_list_prepend (return_list, mount_entry); return_list = g_list_prepend (return_list, mount_entry);
} }
@@ -888,7 +886,6 @@ _g_get_unix_mount_points (void)
{ {
mount_entry = g_new0 (GUnixMountPoint, 1); mount_entry = g_new0 (GUnixMountPoint, 1);
mount_entry->mount_path = g_strdup (mntent.mnt_mount); mount_entry->mount_path = g_strdup (mntent.mnt_mount);
mount_entry->device_path = g_strdup (mntent.mnt_special); mount_entry->device_path = g_strdup (mntent.mnt_special);
mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype); mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
@@ -1061,7 +1058,6 @@ g_unix_mount_at (const char *mount_path,
found = mount_entry; found = mount_entry;
else else
g_unix_mount_free (mount_entry); g_unix_mount_free (mount_entry);
} }
g_list_free (mounts); g_list_free (mounts);
@@ -1147,12 +1143,13 @@ g_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = g_unix_mount_monitor_finalize; gobject_class->finalize = g_unix_mount_monitor_finalize;
/** /**
* GUnixMountMonitor::mounts-changed: * GUnixMountMonitor::mounts-changed:
* @monitor: the object on which the signal is emitted * @monitor: the object on which the signal is emitted
* *
* Emitted when the unix mounts have changed. * Emitted when the unix mounts have changed.
**/ */
signals[MOUNTS_CHANGED] = signals[MOUNTS_CHANGED] =
g_signal_new ("mounts-changed", g_signal_new ("mounts-changed",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
@@ -1161,12 +1158,13 @@ g_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
/** /**
* GUnixMountMonitor::mountpoints-changed: * GUnixMountMonitor::mountpoints-changed:
* @monitor: the object on which the signal is emitted * @monitor: the object on which the signal is emitted
* *
* Emitted when the unix mount points have changed. * Emitted when the unix mount points have changed.
**/ */
signals[MOUNTPOINTS_CHANGED] = signals[MOUNTPOINTS_CHANGED] =
g_signal_new ("mountpoints-changed", g_signal_new ("mountpoints-changed",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
@@ -1247,10 +1245,10 @@ g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
* consecutive change events to the mount and mount point entry files. * consecutive change events to the mount and mount point entry files.
* *
* Since: 2.18 * Since: 2.18
**/ */
void void
g_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount_monitor, g_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount_monitor,
int limit_msec) gint limit_msec)
{ {
g_return_if_fail (G_IS_UNIX_MOUNT_MONITOR (mount_monitor)); g_return_if_fail (G_IS_UNIX_MOUNT_MONITOR (mount_monitor));
@@ -1270,7 +1268,7 @@ g_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount_monitor,
* g_unix_mount_monitor_set_rate_limit() to change this. * g_unix_mount_monitor_set_rate_limit() to change this.
* *
* Returns: a #GUnixMountMonitor. * Returns: a #GUnixMountMonitor.
**/ */
GUnixMountMonitor * GUnixMountMonitor *
g_unix_mount_monitor_new (void) g_unix_mount_monitor_new (void)
{ {
@@ -1288,7 +1286,7 @@ g_unix_mount_monitor_new (void)
* @mount_entry: a #GUnixMount. * @mount_entry: a #GUnixMount.
* *
* Frees a unix mount. * Frees a unix mount.
**/ */
void void
g_unix_mount_free (GUnixMountEntry *mount_entry) g_unix_mount_free (GUnixMountEntry *mount_entry)
{ {
@@ -1305,7 +1303,7 @@ g_unix_mount_free (GUnixMountEntry *mount_entry)
* @mount_point: unix mount point to free. * @mount_point: unix mount point to free.
* *
* Frees a unix mount point. * Frees a unix mount point.
**/ */
void void
g_unix_mount_point_free (GUnixMountPoint *mount_point) g_unix_mount_point_free (GUnixMountPoint *mount_point)
{ {
@@ -1326,7 +1324,7 @@ g_unix_mount_point_free (GUnixMountPoint *mount_point)
* *
* Returns: 1, 0 or -1 if @mount1 is greater than, equal to, * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
* or less than @mount2, respectively. * or less than @mount2, respectively.
**/ */
gint gint
g_unix_mount_compare (GUnixMountEntry *mount1, g_unix_mount_compare (GUnixMountEntry *mount1,
GUnixMountEntry *mount2) GUnixMountEntry *mount2)
@@ -1361,8 +1359,8 @@ g_unix_mount_compare (GUnixMountEntry *mount1,
* Gets the mount path for a unix mount. * Gets the mount path for a unix mount.
* *
* Returns: the mount path for @mount_entry. * Returns: the mount path for @mount_entry.
**/ */
const char * const gchar *
g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry) g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
{ {
g_return_val_if_fail (mount_entry != NULL, NULL); g_return_val_if_fail (mount_entry != NULL, NULL);
@@ -1377,8 +1375,8 @@ g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
* Gets the device path for a unix mount. * Gets the device path for a unix mount.
* *
* Returns: a string containing the device path. * Returns: a string containing the device path.
**/ */
const char * const gchar *
g_unix_mount_get_device_path (GUnixMountEntry *mount_entry) g_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
{ {
g_return_val_if_fail (mount_entry != NULL, NULL); g_return_val_if_fail (mount_entry != NULL, NULL);
@@ -1393,8 +1391,8 @@ g_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
* Gets the filesystem type for the unix mount. * Gets the filesystem type for the unix mount.
* *
* Returns: a string containing the file system type. * Returns: a string containing the file system type.
**/ */
const char * const gchar *
g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry) g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
{ {
g_return_val_if_fail (mount_entry != NULL, NULL); g_return_val_if_fail (mount_entry != NULL, NULL);
@@ -1409,7 +1407,7 @@ g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
* Checks if a unix mount is mounted read only. * Checks if a unix mount is mounted read only.
* *
* Returns: %TRUE if @mount_entry is read only. * Returns: %TRUE if @mount_entry is read only.
**/ */
gboolean gboolean
g_unix_mount_is_readonly (GUnixMountEntry *mount_entry) g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
{ {
@@ -1425,7 +1423,7 @@ g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
* Checks if a unix mount is a system path. * Checks if a unix mount is a system path.
* *
* Returns: %TRUE if the unix mount is for a system path. * Returns: %TRUE if the unix mount is for a system path.
**/ */
gboolean gboolean
g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry) g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
{ {
@@ -1443,7 +1441,7 @@ g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
* *
* Returns: 1, 0 or -1 if @mount1 is greater than, equal to, * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
* or less than @mount2, respectively. * or less than @mount2, respectively.
**/ */
gint gint
g_unix_mount_point_compare (GUnixMountPoint *mount1, g_unix_mount_point_compare (GUnixMountPoint *mount1,
GUnixMountPoint *mount2) GUnixMountPoint *mount2)
@@ -1486,8 +1484,8 @@ g_unix_mount_point_compare (GUnixMountPoint *mount1,
* Gets the mount path for a unix mount point. * Gets the mount path for a unix mount point.
* *
* Returns: a string containing the mount path. * Returns: a string containing the mount path.
**/ */
const char * const gchar *
g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point) g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
{ {
g_return_val_if_fail (mount_point != NULL, NULL); g_return_val_if_fail (mount_point != NULL, NULL);
@@ -1502,8 +1500,8 @@ g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
* Gets the device path for a unix mount point. * Gets the device path for a unix mount point.
* *
* Returns: a string containing the device path. * Returns: a string containing the device path.
**/ */
const char * const gchar *
g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point) g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
{ {
g_return_val_if_fail (mount_point != NULL, NULL); g_return_val_if_fail (mount_point != NULL, NULL);
@@ -1518,8 +1516,8 @@ g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
* Gets the file system type for the mount point. * Gets the file system type for the mount point.
* *
* Returns: a string containing the file system type. * Returns: a string containing the file system type.
**/ */
const char * const gchar *
g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point) g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
{ {
g_return_val_if_fail (mount_point != NULL, NULL); g_return_val_if_fail (mount_point != NULL, NULL);
@@ -1534,7 +1532,7 @@ g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
* Checks if a unix mount point is read only. * Checks if a unix mount point is read only.
* *
* Returns: %TRUE if a mount point is read only. * Returns: %TRUE if a mount point is read only.
**/ */
gboolean gboolean
g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point) g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
{ {
@@ -1550,7 +1548,7 @@ g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
* Checks if a unix mount point is mountable by the user. * Checks if a unix mount point is mountable by the user.
* *
* Returns: %TRUE if the mount point is user mountable. * Returns: %TRUE if the mount point is user mountable.
**/ */
gboolean gboolean
g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point) g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
{ {
@@ -1566,7 +1564,7 @@ g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
* Checks if a unix mount point is a loopback device. * Checks if a unix mount point is a loopback device.
* *
* Returns: %TRUE if the mount point is a loopback. %FALSE otherwise. * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise.
**/ */
gboolean gboolean
g_unix_mount_point_is_loopback (GUnixMountPoint *mount_point) g_unix_mount_point_is_loopback (GUnixMountPoint *mount_point)
{ {
@@ -1663,7 +1661,7 @@ guess_mount_type (const char *mount_path,
* determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN. * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
* *
* Returns: a #GUnixMountType. * Returns: a #GUnixMountType.
**/ */
static GUnixMountType static GUnixMountType
g_unix_mount_guess_type (GUnixMountEntry *mount_entry) g_unix_mount_guess_type (GUnixMountEntry *mount_entry)
{ {
@@ -1686,7 +1684,7 @@ g_unix_mount_guess_type (GUnixMountEntry *mount_entry)
* returns %G_UNIX_MOUNT_TYPE_UNKNOWN. * returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
* *
* Returns: a #GUnixMountType. * Returns: a #GUnixMountType.
**/ */
static GUnixMountType static GUnixMountType
g_unix_mount_point_guess_type (GUnixMountPoint *mount_point) g_unix_mount_point_guess_type (GUnixMountPoint *mount_point)
{ {
@@ -1774,7 +1772,7 @@ type_to_icon (GUnixMountType type, gboolean is_mount_point)
* Returns: A newly allocated string that must * Returns: A newly allocated string that must
* be freed with g_free() * be freed with g_free()
*/ */
char * gchar *
g_unix_mount_guess_name (GUnixMountEntry *mount_entry) g_unix_mount_guess_name (GUnixMountEntry *mount_entry)
{ {
char *name; char *name;
@@ -1811,7 +1809,7 @@ g_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
* Returns: A newly allocated string that must * Returns: A newly allocated string that must
* be freed with g_free() * be freed with g_free()
*/ */
char * gchar *
g_unix_mount_point_guess_name (GUnixMountPoint *mount_point) g_unix_mount_point_guess_name (GUnixMountPoint *mount_point)
{ {
char *name; char *name;
@@ -1881,7 +1879,8 @@ g_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
mount_path = mount_entry->mount_path; mount_path = mount_entry->mount_path;
if (mount_path != NULL) if (mount_path != NULL)
{ {
if (g_str_has_prefix (mount_path, "/media/")) { if (g_str_has_prefix (mount_path, "/media/"))
{
char *path; char *path;
/* Avoid displaying mounts that are not accessible to the user. /* Avoid displaying mounts that are not accessible to the user.
* *
@@ -1892,7 +1891,8 @@ g_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
path = g_path_get_dirname (mount_path); path = g_path_get_dirname (mount_path);
if (g_str_has_prefix (path, "/media/")) if (g_str_has_prefix (path, "/media/"))
{ {
if (g_access (path, R_OK|X_OK) != 0) { if (g_access (path, R_OK|X_OK) != 0)
{
g_free (path); g_free (path);
return FALSE; return FALSE;
} }
@@ -1910,7 +1910,8 @@ g_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
return TRUE; return TRUE;
} }
if (g_str_has_prefix (mount_path, g_get_home_dir ()) && mount_path[strlen (g_get_home_dir())] == G_DIR_SEPARATOR) if (g_str_has_prefix (mount_path, g_get_home_dir ()) &&
mount_path[strlen (g_get_home_dir())] == G_DIR_SEPARATOR)
return TRUE; return TRUE;
} }
@@ -2020,9 +2021,11 @@ _resolve_symlink (const char *file)
f = g_strdup (file); f = g_strdup (file);
while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) { while (g_file_test (f, G_FILE_TEST_IS_SYMLINK))
{
link = g_file_read_link (f, &error); link = g_file_read_link (f, &error);
if (link == NULL) { if (link == NULL)
{
g_error_free (error); g_error_free (error);
g_free (f); g_free (f);
f = NULL; f = NULL;
@@ -2058,8 +2061,10 @@ _resolve_dev_root (void)
/* otherwise we're going to find it right away.. */ /* otherwise we're going to find it right away.. */
have_real_dev_root = TRUE; have_real_dev_root = TRUE;
if (stat ("/dev/root", &statbuf) == 0) { if (stat ("/dev/root", &statbuf) == 0)
if (! S_ISLNK (statbuf.st_mode)) { {
if (! S_ISLNK (statbuf.st_mode))
{
dev_t root_dev = statbuf.st_dev; dev_t root_dev = statbuf.st_dev;
FILE *f; FILE *f;
char buf[1024]; char buf[1024];
@@ -2068,17 +2073,21 @@ _resolve_dev_root (void)
* in /etc/mtab (it usually is) * in /etc/mtab (it usually is)
*/ */
f = fopen ("/etc/mtab", "r"); f = fopen ("/etc/mtab", "r");
if (f != NULL) { if (f != NULL)
{
struct mntent *entp; struct mntent *entp;
#ifdef HAVE_GETMNTENT_R #ifdef HAVE_GETMNTENT_R
struct mntent ent; struct mntent ent;
while ((entp = getmntent_r (f, &ent, buf, sizeof (buf))) != NULL) { while ((entp = getmntent_r (f, &ent, buf, sizeof (buf))) != NULL)
{
#else #else
G_LOCK (getmntent); G_LOCK (getmntent);
while ((entp = getmntent (f)) != NULL) { while ((entp = getmntent (f)) != NULL)
{
#endif #endif
if (stat (entp->mnt_fsname, &statbuf) == 0 && if (stat (entp->mnt_fsname, &statbuf) == 0 &&
statbuf.st_dev == root_dev) { statbuf.st_dev == root_dev)
{
strncpy (real_dev_root, entp->mnt_fsname, sizeof (real_dev_root) - 1); strncpy (real_dev_root, entp->mnt_fsname, sizeof (real_dev_root) - 1);
real_dev_root[sizeof (real_dev_root) - 1] = '\0'; real_dev_root[sizeof (real_dev_root) - 1] = '\0';
fclose (f); fclose (f);
@@ -2095,10 +2104,13 @@ _resolve_dev_root (void)
/* no, that didn't work.. next we could scan /dev ... but I digress.. */ /* no, that didn't work.. next we could scan /dev ... but I digress.. */
} else { }
else
{
char *resolved; char *resolved;
resolved = _resolve_symlink ("/dev/root"); resolved = _resolve_symlink ("/dev/root");
if (resolved != NULL) { if (resolved != NULL)
{
strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1); strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1);
real_dev_root[sizeof (real_dev_root) - 1] = '\0'; real_dev_root[sizeof (real_dev_root) - 1] = '\0';
g_free (resolved); g_free (resolved);
@@ -2110,7 +2122,7 @@ _resolve_dev_root (void)
/* bah sucks.. */ /* bah sucks.. */
strcpy (real_dev_root, "/dev/root"); strcpy (real_dev_root, "/dev/root");
found: found:
return real_dev_root; return real_dev_root;
} }
#endif #endif