From: <hu...@us...> - 2010-02-01 21:00:05
|
Revision: 12677 http://gphoto.svn.sourceforge.net/gphoto/?rev=12677&view=rev Author: hun Date: 2010-02-01 20:59:56 +0000 (Mon, 01 Feb 2010) Log Message: ----------- Replace all %m format strings %m is a glibc extension and can be replaced by %s and strerror(errno). On systems not supporting %m, the output formerly contained a literal %m, which will now be the real error message. We also explititly save errno in a temporary variable saved_errno now to make sure that e.g. the _() translation calls do not modify errno before errno is used to determine the corresponding error message string. Modified Paths: -------------- trunk/libgphoto2/camlibs/directory/directory.c trunk/libgphoto2/libgphoto2_port/serial/unix.c trunk/libgphoto2/libgphoto2_port/usb/libusb.c Modified: trunk/libgphoto2/camlibs/directory/directory.c =================================================================== --- trunk/libgphoto2/camlibs/directory/directory.c 2010-02-01 17:48:11 UTC (rev 12676) +++ trunk/libgphoto2/camlibs/directory/directory.c 2010-02-01 20:59:56 UTC (rev 12677) @@ -347,8 +347,10 @@ /* lstat ... do not follow symlinks */ if (lstat (buf, &st) != 0) { + int saved_errno = errno; gp_context_error (context, _("Could not get information " - "about '%s' (%m)."), buf); + "about '%s' (%s)."), + buf, strerror(saved_errno)); return GP_ERROR; } if (S_ISDIR (st.st_mode)) { @@ -377,8 +379,10 @@ return result; if (lstat (path, &st) != 0) { + int saved_errno = errno; gp_context_error (context, _("Could not get information " - "about '%s' in '%s' (%m)."), file, folder); + "about '%s' in '%s' (%s)."), + file, folder, strerror(saved_errno)); return (GP_ERROR); } @@ -423,9 +427,10 @@ utimbuf.actime = info.file.mtime; utimbuf.modtime = info.file.mtime; if (utime (path, &utimbuf) != 0) { + int saved_errno = errno; gp_context_error (context, _("Could not change " - "time of file '%s' in '%s' (%m)."), - file, folder); + "time of file '%s' in '%s' (%s)."), + file, folder, strerror(saved_errno)); return (GP_ERROR); } } @@ -626,9 +631,10 @@ return result; result = unlink (path); if (result) { + int saved_errno = errno; gp_context_error (context, _("Could not delete file '%s' " - "in folder '%s' (error code %i: %m)."), - file, folder, result); + "in folder '%s' (error code %i: %s)."), + file, folder, result, strerror(saved_errno)); return (GP_ERROR); } Modified: trunk/libgphoto2/libgphoto2_port/serial/unix.c =================================================================== --- trunk/libgphoto2/libgphoto2_port/serial/unix.c 2010-02-01 17:48:11 UTC (rev 12676) +++ trunk/libgphoto2/libgphoto2_port/serial/unix.c 2010-02-01 20:59:56 UTC (rev 12677) @@ -457,7 +457,9 @@ dev->pl->fd = open (port, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK); #endif if (dev->pl->fd == -1) { - gp_port_set_error (dev, _("Failed to open '%s' (%m)."), port); + int saved_errno = errno; + gp_port_set_error (dev, _("Failed to open '%s' (%s)."), + port, strerror(saved_errno)); dev->pl->fd = 0; return GP_ERROR_IO; } @@ -475,8 +477,11 @@ if (dev->pl->fd) { if (close (dev->pl->fd) == -1) { + int saved_errno = errno; gp_port_set_error (dev, _("Could not close " - "'%s' (%m)."), dev->settings.serial.port); + "'%s' (%s)."), + dev->settings.serial.port, + strerror(saved_errno)); return GP_ERROR_IO; } dev->pl->fd = 0; @@ -523,14 +528,16 @@ */ ret = write (dev->pl->fd, bytes, size - len); if (ret == -1) { - switch (errno) { + int saved_errno = errno; + switch (saved_errno) { case EAGAIN: case EINTR: ret = 0; break; default: gp_port_set_error (dev, _("Could not write " - "to port (%m)")); + "to port (%s)"), + strerror(saved_errno)); return GP_ERROR_IO_WRITE; } } @@ -675,8 +682,10 @@ #ifdef HAVE_TERMIOS_H CHECK (get_termios_bit (dev, pin, &bit)); if (ioctl (dev->pl->fd, TIOCMGET, &j) < 0) { + int saved_errno = errno; gp_port_set_error (dev, _("Could not get level of pin %i " - "(%m)."), pin); + "(%s)."), + pin, strerror(saved_errno)); return GP_ERROR_IO; } *level = j & bit; @@ -710,8 +719,10 @@ break; } if (ioctl (dev->pl->fd, request, &bit) < 0) { + int saved_errno = errno; gp_port_set_error (dev, _("Could not set level of pin %i to " - "%i (%m)."), pin, level); + "%i (%s)."), + pin, level, strerror(saved_errno)); return GP_ERROR_IO; } #else @@ -735,8 +746,10 @@ #ifdef HAVE_TERMIOS_H if (tcflush (dev->pl->fd, direction ? TCOFLUSH : TCIFLUSH) < 0) { - gp_port_set_error (dev, _("Could not flush '%s' (%m)."), - dev->settings.serial.port); + int saved_errno = errno; + gp_port_set_error (dev, _("Could not flush '%s' (%s)."), + dev->settings.serial.port, + strerror(saved_errno)); return (GP_ERROR_IO); } #else Modified: trunk/libgphoto2/libgphoto2_port/usb/libusb.c =================================================================== --- trunk/libgphoto2/libgphoto2_port/usb/libusb.c 2010-02-01 17:48:11 UTC (rev 12676) +++ trunk/libgphoto2/libgphoto2_port/usb/libusb.c 2010-02-01 20:59:56 UTC (rev 12677) @@ -248,7 +248,9 @@ */ port->pl->dh = usb_open (port->pl->d); if (!port->pl->dh) { - gp_port_set_error (port, _("Could not open USB device (%m).")); + int saved_errno = errno; + gp_port_set_error (port, _("Could not open USB device (%s)."), + strerror(saved_errno)); return GP_ERROR_IO; } #if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) @@ -279,11 +281,15 @@ ret = usb_claim_interface (port->pl->dh, port->settings.usb.interface); if (ret < 0) { - gp_port_set_error (port, _("Could not claim " - "interface %d (%m). Make sure no other program " - "or kernel module (such as %s) is using the device " - "and you have read/write access to the device."), - port->settings.usb.interface, "sdc2xx, stv680, spca50x"); + int saved_errno = errno; + gp_port_set_error (port, _("Could not claim interface %d (%s). " + "Make sure no other program " + "or kernel module (such as %s) " + "is using the device and you have " + "read/write access to the device."), + port->settings.usb.interface, + strerror(saved_errno), + "sdc2xx, stv680, spca50x"); return GP_ERROR_IO_USB_CLAIM; } return GP_OK; @@ -297,9 +303,11 @@ if (usb_release_interface (port->pl->dh, port->settings.usb.interface) < 0) { - gp_port_set_error (port, _("Could not " - "release interface %d (%m)."), - port->settings.usb.interface); + int saved_errno = errno; + gp_port_set_error (port, _("Could not release " + "interface %d (%s)."), + port->settings.usb.interface, + strerror(saved_errno)); return (GP_ERROR_IO); } @@ -310,7 +318,10 @@ */ if (port->pl->d->descriptor.idVendor == 0x04a9) { if (usb_reset (port->pl->dh) < 0) { - gp_port_set_error (port, _("Could not reset USB port (%m).")); + int saved_errno = errno; + gp_port_set_error (port, _("Could not reset " + "USB port (%s)."), + strerror(saved_errno)); return (GP_ERROR_IO); } } @@ -337,7 +348,9 @@ #endif if (usb_close (port->pl->dh) < 0) { - gp_port_set_error (port, _("Could not close USB port (%m).")); + int saved_errno = errno; + gp_port_set_error (port, _("Could not close USB port (%s)."), + strerror(saved_errno)); return (GP_ERROR_IO); } @@ -585,10 +598,12 @@ port->settings.usb.config); if (ret < 0) { #if 0 /* setting the configuration failure is not fatal */ + int saved_errno = errno; gp_port_set_error (port, - _("Could not set config %d/%d (%m)"), - port->settings.usb.interface, - port->settings.usb.config); + _("Could not set config %d/%d (%s)"), + port->settings.usb.interface, + port->settings.usb.config, + strerror(saved_errno)); return GP_ERROR_IO_UPDATE; #endif gp_log (GP_LOG_ERROR, "gphoto2-port-usb","setting configuration from %d to %d failed with ret = %d, but continue...", port->pl->config, port->settings.usb.config, ret); @@ -618,11 +633,13 @@ if (port->settings.usb.altsetting != port->pl->altsetting) { ret = usb_set_altinterface(port->pl->dh, port->settings.usb.altsetting); if (ret < 0) { - gp_port_set_error (port, - _("Could not set altsetting from %d " - "to %d (%m)"), - port->pl->altsetting, - port->settings.usb.altsetting); + int saved_errno = errno; + gp_port_set_error (port, + _("Could not set altsetting from %d " + "to %d (%s)"), + port->pl->altsetting, + port->settings.usb.altsetting, + strerror(saved_errno)); return GP_ERROR_IO_UPDATE; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |