Deleted Added
full compact
msgcat.c (50476) msgcat.c (55837)
1/* $FreeBSD: head/lib/libc/nls/msgcat.c 50476 1999-08-28 00:22:10Z peter $ */
1/* $FreeBSD: head/lib/libc/nls/msgcat.c 55837 2000-01-12 09:23:48Z jasone $ */
2
3/***********************************************************
4Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
5
6 All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and its
9documentation for any purpose and without fee is hereby granted,

--- 270 unchanged lines hidden (view full) ---

280 MCSetT *set;
281 int i;
282
283 if (catd == NULL || catd == NLERR) {
284 errno = EBADF;
285 return -1;
286 }
287
2
3/***********************************************************
4Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
5
6 All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and its
9documentation for any purpose and without fee is hereby granted,

--- 270 unchanged lines hidden (view full) ---

280 MCSetT *set;
281 int i;
282
283 if (catd == NULL || catd == NLERR) {
284 errno = EBADF;
285 return -1;
286 }
287
288 if (cat->loadType != MCLoadAll) close(cat->fd);
288 if (cat->loadType != MCLoadAll) _libc_close(cat->fd);
289 for (i = 0; i < cat->numSets; ++i) {
290 set = cat->sets + i;
291 if (!set->invalid) {
292 free(set->data.str);
293 free(set->u.msgs);
294 }
295 }
296 free(cat->sets);

--- 19 unchanged lines hidden (view full) ---

316 MCSetT *set;
317 long i, j;
318 off_t nextSet;
319
320 cat = (MCCatT *) malloc(sizeof(MCCatT));
321 if (!cat) return(NLERR);
322 cat->loadType = MCLoadBySet;
323
289 for (i = 0; i < cat->numSets; ++i) {
290 set = cat->sets + i;
291 if (!set->invalid) {
292 free(set->data.str);
293 free(set->u.msgs);
294 }
295 }
296 free(cat->sets);

--- 19 unchanged lines hidden (view full) ---

316 MCSetT *set;
317 long i, j;
318 off_t nextSet;
319
320 cat = (MCCatT *) malloc(sizeof(MCCatT));
321 if (!cat) return(NLERR);
322 cat->loadType = MCLoadBySet;
323
324 if ((cat->fd = open(catpath, O_RDONLY)) < 0) {
324 if ((cat->fd = _libc_open(catpath, O_RDONLY)) < 0) {
325 free(cat);
326 return(NLERR);
327 }
328
325 free(cat);
326 return(NLERR);
327 }
328
329 (void)fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
329 (void)_libc_fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
330
330
331 if (read(cat->fd, &header, sizeof(header)) != sizeof(header)) CORRUPT();
331 if (_libc_read(cat->fd, &header, sizeof(header)) != sizeof(header))
332 CORRUPT();
332
333 if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
334
335 if (header.majorVer != MCMajorVer) {
336 free(cat);
337 fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", ERRNAME,
338 catpath, header.majorVer, MCMajorVer);
339 errno = EINVAL;

--- 23 unchanged lines hidden (view full) ---

363 }
364 }
365 free(cat->sets);
366 CORRUPT();
367 }
368
369 /* read in the set header */
370 set = cat->sets + i;
333
334 if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
335
336 if (header.majorVer != MCMajorVer) {
337 free(cat);
338 fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", ERRNAME,
339 catpath, header.majorVer, MCMajorVer);
340 errno = EINVAL;

--- 23 unchanged lines hidden (view full) ---

364 }
365 }
366 free(cat->sets);
367 CORRUPT();
368 }
369
370 /* read in the set header */
371 set = cat->sets + i;
371 if (read(cat->fd, set, sizeof(*set)) != sizeof(*set)) {
372 if (_libc_read(cat->fd, set, sizeof(*set)) != sizeof(*set)) {
372 for (j = 0; j < i; j++) {
373 set = cat->sets + j;
374 if (!set->invalid) {
375 free(set->data.str);
376 free(set->u.msgs);
377 }
378 }
379 free(cat->sets);

--- 22 unchanged lines hidden (view full) ---

402 free(cat->sets);
403 if (res < 0) NOSPACE();
404 CORRUPT();
405 }
406 } else set->invalid = True;
407 nextSet = set->nextSet;
408 }
409 if (cat->loadType == MCLoadAll) {
373 for (j = 0; j < i; j++) {
374 set = cat->sets + j;
375 if (!set->invalid) {
376 free(set->data.str);
377 free(set->u.msgs);
378 }
379 }
380 free(cat->sets);

--- 22 unchanged lines hidden (view full) ---

403 free(cat->sets);
404 if (res < 0) NOSPACE();
405 CORRUPT();
406 }
407 } else set->invalid = True;
408 nextSet = set->nextSet;
409 }
410 if (cat->loadType == MCLoadAll) {
410 close(cat->fd);
411 _libc_close(cat->fd);
411 cat->fd = -1;
412 }
413 return((nl_catd) cat);
414}
415
416static int loadSet(cat, set)
417MCCatT *cat;
418MCSetT *set;
419{
420 MCMsgT *msg;
421 int i;
422
423 /* Get the data */
424 if (lseek(cat->fd, set->data.off, 0) == -1) return(0);
425 if ((set->data.str = malloc(set->dataLen)) == NULL) return(-1);
412 cat->fd = -1;
413 }
414 return((nl_catd) cat);
415}
416
417static int loadSet(cat, set)
418MCCatT *cat;
419MCSetT *set;
420{
421 MCMsgT *msg;
422 int i;
423
424 /* Get the data */
425 if (lseek(cat->fd, set->data.off, 0) == -1) return(0);
426 if ((set->data.str = malloc(set->dataLen)) == NULL) return(-1);
426 if (read(cat->fd, set->data.str, set->dataLen) != set->dataLen) {
427 if (_libc_read(cat->fd, set->data.str, set->dataLen) != set->dataLen) {
427 free(set->data.str); return(0);
428 }
429
430 /* Get the messages */
431 if (lseek(cat->fd, set->u.firstMsg, 0) == -1) {
432 free(set->data.str); return(0);
433 }
434 if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
435 free(set->data.str); return(-1);
436 }
437
438 for (i = 0; i < set->numMsgs; ++i) {
439 msg = set->u.msgs + i;
428 free(set->data.str); return(0);
429 }
430
431 /* Get the messages */
432 if (lseek(cat->fd, set->u.firstMsg, 0) == -1) {
433 free(set->data.str); return(0);
434 }
435 if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
436 free(set->data.str); return(-1);
437 }
438
439 for (i = 0; i < set->numMsgs; ++i) {
440 msg = set->u.msgs + i;
440 if (read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) {
441 if (_libc_read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) {
441 free(set->u.msgs); free(set->data.str); return(0);
442 }
443 if (msg->invalid) {
444 --i;
445 continue;
446 }
447 msg->msg.str = (char *) (set->data.str + msg->msg.off);
448 }
449 set->invalid = False;
450 return(1);
451}
442 free(set->u.msgs); free(set->data.str); return(0);
443 }
444 if (msg->invalid) {
445 --i;
446 continue;
447 }
448 msg->msg.str = (char *) (set->data.str + msg->msg.off);
449 }
450 set->invalid = False;
451 return(1);
452}