[Pcsclite-cvs-commit] r5195 - /trunk/PCSC/src/utils.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Fri Aug 27 12:48:18 UTC 2010


Author: rousseau
Date: Fri Aug 27 12:48:11 2010
New Revision: 5195

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5195
Log:
GetDaemonPid(): use open(3) instead of fopen(3) to avoid an internal
malloc() call and gain some CPU cycles

Modified:
    trunk/PCSC/src/utils.c

Modified: trunk/PCSC/src/utils.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/utils.c?rev=5195&op=diff
==============================================================================
--- trunk/PCSC/src/utils.c (original)
+++ trunk/PCSC/src/utils.c Fri Aug 27 12:48:11 2010
@@ -31,19 +31,19 @@
 
 pid_t GetDaemonPid(void)
 {
-	FILE *f;
+	int fd;
 	pid_t pid;
 
 	/* pids are only 15 bits but 4294967296
 	 * (32 bits in case of a new system use it) is on 10 bytes
 	 */
-	f = fopen(PCSCLITE_RUN_PID, "rb");
-	if (f != NULL)
+	fd = open(PCSCLITE_RUN_PID, O_RDONLY);
+	if (fd >= 0)
 	{
 		char pid_ascii[PID_ASCII_SIZE];
 
-		(void)fgets(pid_ascii, PID_ASCII_SIZE, f);
-		(void)fclose(f);
+		(void)read(fd, pid_ascii, PID_ASCII_SIZE);
+		(void)close(fd);
 
 		pid = atoi(pid_ascii);
 	}




More information about the Pcsclite-cvs-commit mailing list