[LinuxPPS] [PATCH] time_pps_readlink()
Rodolfo Giometti
giometti at linux.it
Fri Aug 11 12:35:56 CEST 2006
Hello,
here a patch to implement a new userland function to simplify userland
code.
By using the time_pps_readlink() function you can move from this code:
+#ifdef PPS_HAVE_FINDPATH
+ /* Get the PPS source's real name */
+ fd = readlink(link, path, STRING_LEN-1);
+ if (fd <= 0)
+ strncpy(path, link, STRING_LEN);
+ else
+ path[fd] = '\0';
+
+ /* Try to find the source */
+ fd = time_pps_findpath(path, STRING_LEN, id, STRING_LEN);
+ if (fd < 0) {
+ msyslog(LOG_ERR, "refclock: cannot find PPS source \"%s\" in the system",
PPS_DEVICE);
+ return 1;
+ }
+ msyslog(LOG_INFO, "refclock: found PPS source \"%s\" at id #%d on \"%s\"", PPS_DEV
ICE, fd, id);
+#endif /* PPS_HAVE_FINDPATH */
to this code:
+#ifdef PPS_HAVE_FINDPATH
+ /* Get the PPS source's real name */
+ time_pps_readlink(link, STRING_LEN, path, STRING_LEN);
+
+ /* Try to find the source */
+ fd = time_pps_findpath(path, STRING_LEN, id, STRING_LEN);
+ if (fd < 0) {
+ msyslog(LOG_ERR, "refclock: cannot find PPS source \"%s\" in the system",
PPS_DEVICE);
+ return 1;
+ }
+ msyslog(LOG_INFO, "refclock: found PPS source \"%s\" at id #%d on \"%s\"", PPS_DEV
ICE, fd, id);
+#endif /* PPS_HAVE_FINDPATH */
You can use the attached patch or just upgrading your GIT repository
from my server and using branch "dev_time_pps_readlink".
Please, let me know what do you think about it.
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: giometti at enneenne.com
Linux Device Driver giometti at gnudd.com
Embedded Systems giometti at linux.it
UNIX programming phone: +39 349 2432127
-------------- next part --------------
diff --git a/include/linux/timepps.h b/include/linux/timepps.h
index 499f849..93fe2bb 100644
--- a/include/linux/timepps.h
+++ b/include/linux/timepps.h
@@ -183,6 +183,7 @@ #else /* !__KERNEL__ */
/* --- 3.4 Functions ------------------------------------------------------- */
+#include <unistd.h>
#include <errno.h>
#include <asm/types.h>
#include <sys/socket.h>
@@ -453,6 +454,22 @@ static __inline int time_pps_findsource(
}
#define PPS_HAVE_FINDPATH 1
+static __inline void time_pps_readlink(char *link, int linklen, char *path, int pathlen)
+{
+ int i;
+
+ i = readlink(link, path, pathlen-1);
+ if (i <= 0) {
+ /* "link" is not a valid symbolic so we directly use it */
+ strncpy(path, link, linklen <= pathlen ? linklen : pathlen);
+ return;
+ }
+
+ /* Return the file name where "link" points to */
+ path[i] = '\0';
+ return;
+}
+
static __inline int time_pps_findpath(char *path, int pathlen, char *idstring, int idlen)
{
int sock;
More information about the LinuxPPS
mailing list