/ Save the block and Min/Max values for this table. */ The problem here is to avoid name duplication, because more than */ one data file can have the same name (but different types) and/or */ the same data file can be used with different block sizes. This is */ why we use Ofn that defaults to the file name but can be set to a */ different name if necessary.
| 901 | /* different name if necessary. */ |
| 902 | /***********************************************************************/ |
| 903 | bool TDBDOS::SaveBlockValues(PGLOBAL g) |
| 904 | { |
| 905 | char filename[_MAX_PATH]; |
| 906 | int lg, n[NZ + 2]; |
| 907 | size_t nbk, ndv, nbm, block = Txfp->Block; |
| 908 | bool rc = false; |
| 909 | FILE *opfile; |
| 910 | PDOSCOL colp; |
| 911 | PDOSDEF defp = (PDOSDEF)To_Def; |
| 912 | |
| 913 | if (defp->GetOptFileName(g, filename)) |
| 914 | return true; |
| 915 | |
| 916 | if (!(opfile = fopen(filename, "wb"))) { |
| 917 | snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR), |
| 918 | "wb", (int)errno, filename); |
| 919 | safe_strcat(g->Message, sizeof(g->Message), ": "); |
| 920 | safe_strcat(g->Message, sizeof(g->Message), strerror(errno)); |
| 921 | |
| 922 | if (trace(1)) |
| 923 | htrc("%s\n", g->Message); |
| 924 | |
| 925 | return true; |
| 926 | } // endif opfile |
| 927 | |
| 928 | memset(n, 0, sizeof(n)); // To avoid valgrind warning |
| 929 | |
| 930 | if (Ftype == RECFM_VAR || defp->Compressed == 2) { |
| 931 | /*******************************************************************/ |
| 932 | /* Write block starting positions into the opt file. */ |
| 933 | /*******************************************************************/ |
| 934 | block++; |
| 935 | lg = sizeof(int); |
| 936 | n[0] = Txfp->Last; n[1] = lg; n[2] = Txfp->Nrec; n[3] = Txfp->Block; |
| 937 | |
| 938 | if (fwrite(n, sizeof(int), NZ, opfile) != NZ) { |
| 939 | snprintf(g->Message, sizeof(g->Message), MSG(OPT_HEAD_WR_ERR), strerror(errno)); |
| 940 | rc = true; |
| 941 | } // endif size |
| 942 | |
| 943 | if (fwrite(Txfp->BlkPos, lg, block, opfile) != block) { |
| 944 | snprintf(g->Message, sizeof(g->Message), MSG(OPTBLK_WR_ERR), strerror(errno)); |
| 945 | rc = true; |
| 946 | } // endif size |
| 947 | |
| 948 | block--; // = Txfp->Block; |
| 949 | } // endif Ftype |
| 950 | |
| 951 | /*********************************************************************/ |
| 952 | /* Write the Min/Max values into the opt file. */ |
| 953 | /*********************************************************************/ |
| 954 | for (colp = (PDOSCOL)Columns; colp; colp = (PDOSCOL)colp->Next) { |
| 955 | lg = colp->Value->GetClen(); |
| 956 | |
| 957 | // Now start the writing process |
| 958 | if (colp->Clustered == 2) { |
| 959 | // New XDB2 block optimization. Will be recognized when reading |
| 960 | // because the column index is negated. |
nothing calls this directly
no test coverage detected