| 618 | } |
| 619 | |
| 620 | NHFILE * |
| 621 | create_levelfile(int lev, char errbuf[]) |
| 622 | { |
| 623 | const char *fq_lock; |
| 624 | NHFILE *nhfp = (NHFILE *) 0; |
| 625 | |
| 626 | if (errbuf) |
| 627 | *errbuf = '\0'; |
| 628 | set_levelfile_name(gl.lock, lev); |
| 629 | fq_lock = fqname(gl.lock, LEVELPREFIX, 0); |
| 630 | |
| 631 | nhfp = new_nhfile(); |
| 632 | if (nhfp) { |
| 633 | nhfp->ftype = NHF_LEVELFILE; |
| 634 | nhfp->mode = WRITING; |
| 635 | nhfp->structlevel = TRUE; /* do set this TRUE for levelfiles */ |
| 636 | nhfp->fieldlevel = FALSE; /* don't set this TRUE for levelfiles */ |
| 637 | nhfp->addinfo = FALSE; |
| 638 | nhfp->style.deflt = FALSE; |
| 639 | nhfp->style.binary = TRUE; |
| 640 | nhfp->fnidx = historical; |
| 641 | nhfp->fd = -1; |
| 642 | nhfp->fpdef = (FILE *) 0; |
| 643 | #if defined(MICRO) || defined(WIN32) |
| 644 | /* Use O_TRUNC to force the file to be shortened if it already |
| 645 | * exists and is currently longer. |
| 646 | */ |
| 647 | nhfp->fd = open(fq_lock, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
| 648 | FCMASK); |
| 649 | #else |
| 650 | #ifdef MACOS9 |
| 651 | nhfp->fd = maccreat(fq_lock, LEVL_TYPE); |
| 652 | #else |
| 653 | nhfp->fd = creat(fq_lock, FCMASK); |
| 654 | #endif |
| 655 | #endif /* MICRO || WIN32 */ |
| 656 | |
| 657 | if (nhfp->fd >= 0) |
| 658 | svl.level_info[lev].flags |= LFILE_EXISTS; |
| 659 | else if (errbuf) /* failure explanation */ |
| 660 | Sprintf(errbuf, |
| 661 | "Cannot create file \"%s\" for level %d (errno %d).", |
| 662 | gl.lock, lev, errno); |
| 663 | #if defined(MSDOS) || defined(WIN32) |
| 664 | if (nhfp->fd >= 0) |
| 665 | (void) setmode(nhfp->fd, O_BINARY); |
| 666 | #endif |
| 667 | } |
| 668 | nhfp = viable_nhfile(nhfp); |
| 669 | return nhfp; |
| 670 | } |
| 671 | |
| 672 | NHFILE * |
| 673 | open_levelfile(int lev, char errbuf[]) |
no test coverage detected