| 830 | } |
| 831 | |
| 832 | NHFILE * |
| 833 | create_bonesfile(d_level *lev, char **bonesid, char errbuf[]) |
| 834 | { |
| 835 | const char *file; |
| 836 | NHFILE *nhfp = (NHFILE *) 0; |
| 837 | int failed = 0; |
| 838 | #if defined(WIN32) |
| 839 | errno_t err; |
| 840 | #endif |
| 841 | |
| 842 | if (errbuf) |
| 843 | *errbuf = '\0'; |
| 844 | *bonesid = set_bonesfile_name(gb.bones, lev); |
| 845 | file = set_bonestemp_name(); |
| 846 | file = fqname(file, BONESPREFIX, 0); |
| 847 | |
| 848 | nhfp = new_nhfile(); |
| 849 | if (nhfp) { |
| 850 | nhfp->ftype = NHF_BONESFILE; |
| 851 | nhfp->mode = WRITING; |
| 852 | nhfp->structlevel = TRUE; |
| 853 | nhfp->fieldlevel = FALSE; |
| 854 | nhfp->addinfo = TRUE; |
| 855 | nhfp->style.deflt = TRUE; |
| 856 | nhfp->style.binary = TRUE; |
| 857 | nhfp->fnidx = historical; |
| 858 | nhfp->fd = -1; |
| 859 | nhfp->fpdef = (FILE *) 0; |
| 860 | if (nhfp->fpdef) { |
| 861 | #ifdef SAVEFILE_DEBUGGING |
| 862 | nhfp->fpdebug = fopen("create_bonesfile-debug.log", "a"); |
| 863 | #endif |
| 864 | } else { |
| 865 | failed = errno; |
| 866 | } |
| 867 | if (nhfp->structlevel) { |
| 868 | #if defined(MICRO) |
| 869 | /* Use O_TRUNC to force the file to be shortened if it already |
| 870 | * exists and is currently longer. |
| 871 | */ |
| 872 | nhfp->fd = open(file, |
| 873 | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, FCMASK); |
| 874 | #elif defined(WIN32) |
| 875 | err = _sopen_s(&nhfp->fd, file, |
| 876 | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
| 877 | _SH_DENYRW, _S_IREAD | _S_IWRITE); |
| 878 | #else /* ?MICRO || WIN32 */ |
| 879 | /* implies UNIX or MACOS9 (MACOS9 is for OS9 or earlier) */ |
| 880 | #ifdef MACOS9 |
| 881 | nhfp->fd = maccreat(file, BONE_TYPE); |
| 882 | #else |
| 883 | nhfp->fd = creat(file, FCMASK); |
| 884 | #endif /* ?MACOS9 */ |
| 885 | #endif /* ?MICRO || WIN32 */ |
| 886 | if (nhfp->fd < 0) |
| 887 | failed = errno; |
| 888 | #if defined(MSDOS) || defined(WIN32) |
| 889 | if (nhfp->fd >= 0) |
no test coverage detected