mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Canonicalize symlinks in portnames
This allows users to supply symlinks created e.g. by udev rules instead of the actual device names.
This commit is contained in:
parent
2a6c24be33
commit
95bad38c5b
@ -126,6 +126,9 @@ AC_CHECK_DECLS([BOTHER],,, [[#include <linux/termios.h>]])
|
|||||||
# Check for serial_struct.
|
# Check for serial_struct.
|
||||||
AC_CHECK_TYPES([struct serial_struct],,, [[#include <linux/serial.h>]])
|
AC_CHECK_TYPES([struct serial_struct],,, [[#include <linux/serial.h>]])
|
||||||
|
|
||||||
|
# Check for realpath().
|
||||||
|
AC_CHECK_FUNC([realpath], [AC_DEFINE(HAVE_REALPATH, 1, [realpath is available.])], [])
|
||||||
|
|
||||||
AC_CACHE_CHECK([for visibility control], [sp_cv_visibility_control], [
|
AC_CACHE_CHECK([for visibility control], [sp_cv_visibility_control], [
|
||||||
sp_saved_CFLAGS=$CFLAGS
|
sp_saved_CFLAGS=$CFLAGS
|
||||||
CFLAGS="$CFLAGS -Werror"
|
CFLAGS="$CFLAGS -Werror"
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* For timeradd, timersub, timercmp. */
|
/* For timeradd, timersub, timercmp, realpath. */
|
||||||
#define _BSD_SOURCE 1 /* for glibc < 2.19 */
|
#define _BSD_SOURCE 1 /* for glibc < 2.19 */
|
||||||
#define _DEFAULT_SOURCE 1 /* for glibc >= 2.20 */
|
#define _DEFAULT_SOURCE 1 /* for glibc >= 2.20 */
|
||||||
#endif
|
#endif
|
||||||
|
14
serialport.c
14
serialport.c
@ -75,6 +75,20 @@ SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port *
|
|||||||
|
|
||||||
DEBUG_FMT("Building structure for port %s", portname);
|
DEBUG_FMT("Building structure for port %s", portname);
|
||||||
|
|
||||||
|
#if !defined(_WIN32) && defined(HAVE_REALPATH)
|
||||||
|
/*
|
||||||
|
* get_port_details() below tries to be too smart and figure out
|
||||||
|
* some transport properties from the port name which breaks with
|
||||||
|
* symlinks. Therefore we canonicalize the portname first.
|
||||||
|
*/
|
||||||
|
char pathbuf[PATH_MAX + 1];
|
||||||
|
char *res = realpath(portname, pathbuf);
|
||||||
|
if (!res)
|
||||||
|
RETURN_ERROR(SP_ERR_ARG, "Could not retrieve realpath behind port name");
|
||||||
|
|
||||||
|
portname = pathbuf;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!(port = malloc(sizeof(struct sp_port))))
|
if (!(port = malloc(sizeof(struct sp_port))))
|
||||||
RETURN_ERROR(SP_ERR_MEM, "Port structure malloc failed");
|
RETURN_ERROR(SP_ERR_MEM, "Port structure malloc failed");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user