Mercurial > pidgin
annotate src/protocols/zephyr/ZReadAscii.c @ 10261:d4e9ff2edc4e
[gaim-migrate @ 11405]
This should fix segfault bug 1072604. Oops.
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Thu, 25 Nov 2004 18:35:26 +0000 |
| parents | 43d6c08d7e96 |
| children | 64895571248f |
| rev | line source |
|---|---|
| 2086 | 1 /* This file is part of the Project Athena Zephyr Notification System. |
| 2 * It contains source for the ZReadAscii function. | |
| 3 * | |
| 4 * Created by: Robert French | |
| 5 * | |
| 6 * $Source$ | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
7 * $Author: chipx86 $ |
| 2086 | 8 * |
| 9 * Copyright (c) 1987, 1990 by the Massachusetts Institute of Technology. | |
| 10 * For copying and distribution information, see the file | |
| 11 * "mit-copyright.h". | |
| 12 */ | |
| 13 /* $Header$ */ | |
| 14 | |
| 15 #ifndef lint | |
| 16 static char rcsid_ZReadAscii_c[] = "$Header$"; | |
| 17 #endif /* lint */ | |
| 18 | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
19 #include "internal.h" |
| 2086 | 20 #include <assert.h> |
| 21 | |
| 22 #if 0 | |
| 23 static __inline__ | |
| 24 int | |
| 25 Z_cnvt_xtoi (char c) | |
| 26 { | |
| 27 c -= '0'; | |
| 28 if (c < 10) | |
| 29 return c; | |
| 30 c -= 'A'-'9'-1; | |
| 31 if (c < 16) | |
| 32 return c; | |
| 33 return -1; | |
| 34 } | |
| 35 #endif | |
| 36 | |
| 37 #define Z_cnvt_xtoi(c) ((temp=(c)-'0'),(temp<10)?temp:((temp-='A'-'9'-1),(temp<16)?temp:-1)) | |
| 38 | |
| 39 Code_t ZReadAscii(ptr, len, field, num) | |
| 40 char *ptr; | |
| 41 int len; | |
| 42 unsigned char *field; | |
| 43 int num; | |
| 44 { | |
| 45 int i; | |
| 46 unsigned int hexbyte; | |
| 47 register int c1, c2; | |
| 48 register unsigned int temp; | |
| 49 | |
| 50 for (i=0;i<num;i++) { | |
| 51 if (*ptr == ' ') { | |
| 52 ptr++; | |
| 53 if (--len < 0) | |
| 54 return ZERR_BADFIELD; | |
| 55 } | |
| 56 if (ptr[0] == '0' && ptr[1] == 'x') { | |
| 57 ptr += 2; | |
| 58 len -= 2; | |
| 59 if (len < 0) | |
| 60 return ZERR_BADFIELD; | |
| 61 } | |
| 62 c1 = Z_cnvt_xtoi(ptr[0]); | |
| 63 if (c1 < 0) | |
| 64 return ZERR_BADFIELD; | |
| 65 c2 = Z_cnvt_xtoi(ptr[1]); | |
| 66 if (c2 < 0) | |
| 67 return ZERR_BADFIELD; | |
| 68 hexbyte = (c1 << 4) | c2; | |
| 69 field[i] = hexbyte; | |
| 70 ptr += 2; | |
| 71 len -= 2; | |
| 72 if (len < 0) | |
| 73 return ZERR_BADFIELD; | |
| 74 } | |
| 75 | |
| 76 return *ptr ? ZERR_BADFIELD : ZERR_NONE; | |
| 77 } | |
| 78 | |
| 79 Code_t ZReadAscii32(ptr, len, value_ptr) | |
| 80 char *ptr; | |
| 81 int len; | |
| 82 unsigned long *value_ptr; | |
| 83 { | |
| 84 unsigned char buf[4]; | |
| 85 Code_t retval; | |
| 86 | |
| 87 retval = ZReadAscii(ptr, len, buf, 4); | |
| 88 if (retval != ZERR_NONE) | |
| 89 return retval; | |
| 90 *value_ptr = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
| 91 return ZERR_NONE; | |
| 92 } | |
| 93 | |
| 94 Code_t ZReadAscii16(ptr, len, value_ptr) | |
| 95 char *ptr; | |
| 96 int len; | |
| 97 unsigned short *value_ptr; | |
| 98 { | |
| 99 unsigned char buf[2]; | |
| 100 Code_t retval; | |
| 101 | |
| 102 retval = ZReadAscii(ptr, len, buf, 2); | |
| 103 if (retval != ZERR_NONE) | |
| 104 return retval; | |
| 105 *value_ptr = (buf[0] << 8) | buf[1]; | |
| 106 return ZERR_NONE; | |
| 107 } | |
| 108 |
