summaryrefslogtreecommitdiff
path: root/libgphoto2_port/disk
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2006-05-31 12:38:47 +0000
committerMarcus Meissner <marcus@jet.franken.de>2006-05-31 12:38:47 +0000
commitde42930dbbb2df13ffb8487a7bf649c511fb01a9 (patch)
treec4569c50f3dba570199236d40c3da552b522fae4 /libgphoto2_port/disk
parentdc4c7ecd73fe2c3112e0e89cb62b32064755156e (diff)
downloadlibgphoto2-de42930dbbb2df13ffb8487a7bf649c511fb01a9.tar.gz
check return values of setmntent() (could return NULL
when fstab or mtab where not there). git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@8834 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port/disk')
-rw-r--r--libgphoto2_port/disk/disk.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/libgphoto2_port/disk/disk.c b/libgphoto2_port/disk/disk.c
index 97875e504..33b0be146 100644
--- a/libgphoto2_port/disk/disk.c
+++ b/libgphoto2_port/disk/disk.c
@@ -187,48 +187,52 @@ gp_port_library_list (GPPortInfoList *list)
info.type = GP_PORT_DISK;
mnt = setmntent ("/etc/fstab", "r");
- while ((mntent = getmntent (mnt))) {
- /* detect floppies so we don't access them with the stat() below */
- if ( (NULL != strstr(mntent->mnt_fsname,"fd")) ||
- (NULL != strstr(mntent->mnt_fsname,"floppy"))
- )
- continue;
-
- snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir);
- if (-1 == stat(path, &stbuf)) {
- snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir);
- if (-1 == stat(path, &stbuf))
+ if (mnt) {
+ while ((mntent = getmntent (mnt))) {
+ /* detect floppies so we don't access them with the stat() below */
+ if ( (NULL != strstr(mntent->mnt_fsname,"fd")) ||
+ (NULL != strstr(mntent->mnt_fsname,"floppy"))
+ )
continue;
+
+ snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir);
+ if (-1 == stat(path, &stbuf)) {
+ snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir);
+ if (-1 == stat(path, &stbuf))
+ continue;
+ }
+ snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname),
+ snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir);
+ if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK)
+ continue;
+ CHECK (gp_port_info_list_append (list, info));
}
- snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname),
- snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir);
- if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK)
- continue;
- CHECK (gp_port_info_list_append (list, info));
+ endmntent(mnt);
}
- endmntent(mnt);
mnt = setmntent ("/etc/mtab", "r");
- while ((mntent = getmntent (mnt))) {
- /* detect floppies so we don't access them with the stat() below */
- if ( (NULL != strstr(mntent->mnt_fsname,"fd")) ||
- (NULL != strstr(mntent->mnt_fsname,"floppy"))
- )
- continue;
-
- snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir);
- if (-1 == stat(path, &stbuf)) {
- snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir);
- if (-1 == stat(path, &stbuf))
+ if (mnt) {
+ while ((mntent = getmntent (mnt))) {
+ /* detect floppies so we don't access them with the stat() below */
+ if ( (NULL != strstr(mntent->mnt_fsname,"fd")) ||
+ (NULL != strstr(mntent->mnt_fsname,"floppy"))
+ )
continue;
+
+ snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir);
+ if (-1 == stat(path, &stbuf)) {
+ snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir);
+ if (-1 == stat(path, &stbuf))
+ continue;
+ }
+ info.type = GP_PORT_DISK;
+ snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname),
+ snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir);
+ if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK)
+ continue;
+ CHECK (gp_port_info_list_append (list, info));
}
- info.type = GP_PORT_DISK;
- snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname),
- snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir);
- if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK)
- continue;
- CHECK (gp_port_info_list_append (list, info));
+ endmntent(mnt);
}
- endmntent(mnt);
# endif
#endif
/* generic disk:/xxx/ matcher */