aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/src/AuRead.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/lib/src/AuRead.c')
-rw-r--r--nx-X11/lib/src/AuRead.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/nx-X11/lib/src/AuRead.c b/nx-X11/lib/src/AuRead.c
index 61814792d..2e21cf0a5 100644
--- a/nx-X11/lib/src/AuRead.c
+++ b/nx-X11/lib/src/AuRead.c
@@ -30,20 +30,23 @@ in this Software without prior written authorization from The Open Group.
#endif
#include <nx-X11/Xauth.h>
#include <stdlib.h>
+#ifdef NX_TRANS_SOCKET
#include <errno.h>
+#endif
static int
read_short (unsigned short *shortp, FILE *file)
{
unsigned char file_short[2];
+#ifdef NX_TRANS_SOCKET
/*
* Added a check on EINTR to prevent the fread() call to be
* interrupted by any signal not blocked by OsBlockSignals().
*/
for (;;) {
- if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) {
+ if (fread ((char *) file_short, sizeof (file_short), 1, file) != 1) {
if (errno == EINTR && ferror (file)) {
perror ("Reading from auth file");
clearerr (file);
@@ -53,6 +56,10 @@ read_short (unsigned short *shortp, FILE *file)
}
break;
}
+#else
+ if (fread ((char *) file_short, sizeof (file_short), 1, file) != 1)
+ return 0;
+#endif
*shortp = file_short[0] * 256 + file_short[1];
return 1;
}
@@ -61,19 +68,20 @@ static int
read_counted_string (unsigned short *countp, char **stringp, FILE *file)
{
unsigned short len;
- char *data;
+ char *data;
if (read_short (&len, file) == 0)
- return 0;
+ return 0;
if (len == 0) {
- data = 0;
+ data = NULL;
} else {
- data = malloc ((unsigned) len);
- if (!data)
- return 0;
+ data = malloc ((unsigned) len);
+ if (!data)
+ return 0;
+#ifdef NX_TRANS_SOCKET
for (;;)
{
- if (fread (data, (int) sizeof (char), (int) len, file) != len)
+ if (fread (data, sizeof (char), len, file) != len)
{
if (errno == EINTR && ferror (file))
{
@@ -81,12 +89,19 @@ read_counted_string (unsigned short *countp, char **stringp, FILE *file)
clearerr (file);
continue;
}
- bzero (data, len);
- free (data);
- return 0;
- }
+ bzero (data, len);
+ free (data);
+ return 0;
+ }
break;
}
+#else
+ if (fread (data, sizeof (char), len, file) != len) {
+ bzero (data, len);
+ free (data);
+ return 0;
+ }
+#endif
}
*stringp = data;
*countp = len;
@@ -94,41 +109,40 @@ read_counted_string (unsigned short *countp, char **stringp, FILE *file)
}
Xauth *
-XauReadAuth (auth_file)
-FILE *auth_file;
+XauReadAuth (FILE *auth_file)
{
Xauth local;
Xauth *ret;
if (read_short (&local.family, auth_file) == 0)
- return 0;
+ return NULL;
if (read_counted_string (&local.address_length, &local.address, auth_file) == 0)
- return 0;
+ return NULL;
if (read_counted_string (&local.number_length, &local.number, auth_file) == 0) {
- if (local.address) free (local.address);
- return 0;
+ free (local.address);
+ return NULL;
}
if (read_counted_string (&local.name_length, &local.name, auth_file) == 0) {
- if (local.address) free (local.address);
- if (local.number) free (local.number);
- return 0;
+ free (local.address);
+ free (local.number);
+ return NULL;
}
if (read_counted_string (&local.data_length, &local.data, auth_file) == 0) {
- if (local.address) free (local.address);
- if (local.number) free (local.number);
- if (local.name) free (local.name);
- return 0;
+ free (local.address);
+ free (local.number);
+ free (local.name);
+ return NULL;
}
ret = (Xauth *) malloc (sizeof (Xauth));
if (!ret) {
- if (local.address) free (local.address);
- if (local.number) free (local.number);
- if (local.name) free (local.name);
- if (local.data) {
- bzero (local.data, local.data_length);
- free (local.data);
- }
- return 0;
+ free (local.address);
+ free (local.number);
+ free (local.name);
+ if (local.data) {
+ bzero (local.data, local.data_length);
+ free (local.data);
+ }
+ return NULL;
}
*ret = local;
return ret;