Changeset 80f345c in mainline
- Timestamp:
- 2018-06-14T12:40:20Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be2a20ac
- Parents:
- f4aa1c8
- git-author:
- Jiri Svoboda <jiri@…> (2018-06-13 21:39:34)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-06-14 12:40:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/stdio/scanf.c
rf4aa1c8 r80f345c 126 126 size_t size; 127 127 } strbuf_t; 128 129 /** Wrapper needed to pass va_list around by reference in a portable fashion */ 130 typedef struct { 131 va_list ap; 132 } va_encaps_t; 128 133 129 134 static int digit_value(char digit) … … 343 348 * @return EOK on success, ENOMEM if out of memory 344 349 */ 345 static int strbuf_init(strbuf_t *strbuf, cvtspec_t *spec, va_ list ap)350 static int strbuf_init(strbuf_t *strbuf, cvtspec_t *spec, va_encaps_t *va) 346 351 { 347 352 if (spec->noassign) { … … 365 370 * location 366 371 */ 367 strbuf->pptr = va_arg( ap, char **);372 strbuf->pptr = va_arg(va->ap, char **); 368 373 *strbuf->pptr = strbuf->buf; 369 374 } else { … … 371 376 strbuf->memalloc = false; 372 377 strbuf->size = 0; 373 strbuf->buf = va_arg( ap, char *);378 strbuf->buf = va_arg(va->ap, char *); 374 379 strbuf->pptr = NULL; 375 380 } … … 985 990 986 991 /** Perform a single conversion. */ 987 static int vfscanf_cvt(FILE *f, const char **fmt, va_ list ap, int *numchar,988 unsigned *ncvt)992 static int vfscanf_cvt(FILE *f, const char **fmt, va_encaps_t *va, 993 int *numchar, unsigned *ncvt) 989 994 { 990 995 int rc; … … 1089 1094 case cs_char: 1090 1095 /* Characters */ 1091 rc = strbuf_init(&strbuf, &cvtspec, ap);1096 rc = strbuf_init(&strbuf, &cvtspec, va); 1092 1097 if (rc != EOK) 1093 1098 return rc; … … 1108 1113 case cs_str: 1109 1114 /* Non-whitespace string */ 1110 rc = strbuf_init(&strbuf, &cvtspec, ap);1115 rc = strbuf_init(&strbuf, &cvtspec, va); 1111 1116 if (rc != EOK) 1112 1117 return rc; … … 1127 1132 case cs_set: 1128 1133 /* String of characters from scanset */ 1129 rc = strbuf_init(&strbuf, &cvtspec, ap);1134 rc = strbuf_init(&strbuf, &cvtspec, va); 1130 1135 if (rc != EOK) 1131 1136 return rc; … … 1163 1168 switch (cvtspec.lenmod) { 1164 1169 case lm_none: 1165 iptr = va_arg( ap, int *);1170 iptr = va_arg(va->ap, int *); 1166 1171 *iptr = ival; 1167 1172 break; 1168 1173 case lm_hh: 1169 scptr = va_arg( ap, signed char *);1174 scptr = va_arg(va->ap, signed char *); 1170 1175 *scptr = ival; 1171 1176 break; 1172 1177 case lm_h: 1173 sptr = va_arg( ap, short *);1178 sptr = va_arg(va->ap, short *); 1174 1179 *sptr = ival; 1175 1180 break; 1176 1181 case lm_l: 1177 lptr = va_arg( ap, long *);1182 lptr = va_arg(va->ap, long *); 1178 1183 *lptr = ival; 1179 1184 break; 1180 1185 case lm_ll: 1181 llptr = va_arg( ap, long long *);1186 llptr = va_arg(va->ap, long long *); 1182 1187 *llptr = ival; 1183 1188 break; 1184 1189 case lm_j: 1185 imptr = va_arg( ap, intmax_t *);1190 imptr = va_arg(va->ap, intmax_t *); 1186 1191 *imptr = ival; 1187 1192 break; 1188 1193 case lm_z: 1189 ssptr = va_arg( ap, ssize_t *);1194 ssptr = va_arg(va->ap, ssize_t *); 1190 1195 *ssptr = ival; 1191 1196 break; 1192 1197 case lm_t: 1193 pdptr = va_arg( ap, ptrdiff_t *);1198 pdptr = va_arg(va->ap, ptrdiff_t *); 1194 1199 *pdptr = ival; 1195 1200 break; … … 1205 1210 switch (cvtspec.lenmod) { 1206 1211 case lm_none: 1207 uptr = va_arg( ap, unsigned *);1212 uptr = va_arg(va->ap, unsigned *); 1208 1213 *uptr = uval; 1209 1214 break; 1210 1215 case lm_hh: 1211 ucptr = va_arg( ap, unsigned char *);1216 ucptr = va_arg(va->ap, unsigned char *); 1212 1217 *ucptr = uval; 1213 1218 break; 1214 1219 case lm_h: 1215 usptr = va_arg( ap, unsigned short *);1220 usptr = va_arg(va->ap, unsigned short *); 1216 1221 *usptr = uval; 1217 1222 break; 1218 1223 case lm_l: 1219 ulptr = va_arg( ap, unsigned long *);1224 ulptr = va_arg(va->ap, unsigned long *); 1220 1225 *ulptr = uval; 1221 1226 break; 1222 1227 case lm_ll: 1223 ullptr = va_arg( ap, unsigned long long *);1228 ullptr = va_arg(va->ap, unsigned long long *); 1224 1229 *ullptr = uval; 1225 1230 break; 1226 1231 case lm_j: 1227 umptr = va_arg( ap, uintmax_t *);1232 umptr = va_arg(va->ap, uintmax_t *); 1228 1233 *umptr = uval; 1229 1234 break; 1230 1235 case lm_z: 1231 szptr = va_arg( ap, size_t *);1236 szptr = va_arg(va->ap, size_t *); 1232 1237 *szptr = uval; 1233 1238 break; 1234 1239 case lm_t: 1235 updptr = va_arg( ap, ptrdiff_t *);1240 updptr = va_arg(va->ap, ptrdiff_t *); 1236 1241 *updptr = uval; 1237 1242 break; … … 1245 1250 switch (cvtspec.lenmod) { 1246 1251 case lm_none: 1247 fptr = va_arg( ap, float *);1252 fptr = va_arg(va->ap, float *); 1248 1253 *fptr = fval; 1249 1254 break; 1250 1255 case lm_l: 1251 dptr = va_arg( ap, double *);1256 dptr = va_arg(va->ap, double *); 1252 1257 *dptr = fval; 1253 1258 break; 1254 1259 case lm_L: 1255 ldptr = va_arg( ap, long double *);1260 ldptr = va_arg(va->ap, long double *); 1256 1261 *ldptr = fval; 1257 1262 break; … … 1263 1268 break; 1264 1269 case cs_ptr: 1265 pptr = va_arg( ap, void *);1270 pptr = va_arg(va->ap, void *); 1266 1271 *pptr = (void *)(uintptr_t)uval; 1267 1272 ++(*ncvt); … … 1278 1283 case cs_numchar: 1279 1284 /* Store number of characters read so far. */ 1280 iptr = va_arg( ap, int *);1285 iptr = va_arg(va->ap, int *); 1281 1286 *iptr = *numchar; 1282 1287 /* No incrementing of ncvt */ … … 1298 1303 int numchar; 1299 1304 bool input_error = false; 1305 va_encaps_t va; 1300 1306 int rc; 1307 1308 va_copy(va.ap, ap); 1301 1309 1302 1310 ncvt = 0; … … 1315 1323 } else if (*cp == '%') { 1316 1324 /* Conversion specification */ 1317 rc = vfscanf_cvt(f, &cp, ap, &numchar, &ncvt); 1325 rc = vfscanf_cvt(f, &cp, &va, &numchar, 1326 &ncvt); 1318 1327 if (rc == EIO) { 1319 1328 /* Input error */
Note:
See TracChangeset
for help on using the changeset viewer.