Skip to content

Commit 6ea4f36

Browse files
committed
Add fileClose2()
1 parent edc799b commit 6ea4f36

10 files changed

Lines changed: 51 additions & 33 deletions

File tree

cmd/bsum/bsum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Hash files using belt-hash / bash-hash
55
\project bee2/cmd
66
\created 2014.10.28
7-
\version 2025.05.07
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -184,7 +184,7 @@ static int bsumHash(octet hash[], size_t hid, const char* name)
184184
}
185185
while (count == sizeof(buf));
186186
// закрыть файл
187-
if (!fileClose(file))
187+
if (!fileClose2(file))
188188
{
189189
memWipe(buf, sizeof(buf));
190190
memWipe(state, sizeof(state));
@@ -275,7 +275,7 @@ static int bsumCheck(size_t hid, const char* name)
275275
printf("%s: OK\n", str + 2 * hash_len + 2);
276276
}
277277
// закрыть файл контрольных сумм
278-
if (!fileClose(file))
278+
if (!fileClose2(file))
279279
{
280280
printf("%s: FAILED [close]\n", name);
281281
return -1;

cmd/cmd.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Command-line interface to Bee2
55
\project bee2/cmd
66
\created 2022.06.09
7-
\version 2025.05.05
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -314,7 +314,11 @@ err_t cmdPrintDate(
314314

315315
/*! \brief Закрытие файла */
316316
#define cmdFileClose(file) \
317-
(fileClose(file) ? ERR_OK : ERR_BAD_FILE)
317+
(fileClose(file))
318+
319+
/*! \brief Закрытие файла с контролем */
320+
#define cmdFileClose2(file) \
321+
(fileClose2(file) ? ERR_OK : ERR_BAD_FILE)
318322

319323
/*! \brief Размер файла
320324

cmd/core/cmd_file.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Command-line interface to Bee2: file management
55
\project bee2/cmd
66
\created 2022.06.08
7-
\version 2025.04.25
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -37,7 +37,7 @@ size_t cmdFileSize(const char* name)
3737
code = cmdFileOpen(file, name, "rb");
3838
ERR_CALL_CHECK(code);
3939
size = fileSize(file);
40-
code = cmdFileClose(file);
40+
code = cmdFileClose2(file);
4141
return (size == SIZE_MAX || code != ERR_OK) ? SIZE_MAX : size;
4242
}
4343

@@ -59,7 +59,7 @@ err_t cmdFileWrite(const char* name, const void* buf, size_t count)
5959
ERR_CALL_CHECK(code);
6060
code = fileWrite(&count, buf, count, file);
6161
ERR_CALL_HANDLE(code, cmdFileClose(file));
62-
return cmdFileClose(file);
62+
return cmdFileClose2(file);
6363
}
6464

6565
err_t cmdFilePrepend(const char* name, const void* buf, size_t count)
@@ -116,7 +116,7 @@ err_t cmdFilePrepend(const char* name, const void* buf, size_t count)
116116
code = fileWrite(&count, buf, count, file);
117117
ERR_CALL_HANDLE(code, cmdFileClose(file));
118118
// завершить
119-
return cmdFileClose(file);
119+
return cmdFileClose2(file);
120120
}
121121

122122
err_t cmdFileAppend(const char* name, const void* buf, size_t count)
@@ -131,7 +131,7 @@ err_t cmdFileAppend(const char* name, const void* buf, size_t count)
131131
ERR_CALL_CHECK(code);
132132
code = fileWrite(&count, buf, count, file);
133133
ERR_CALL_HANDLE(code, cmdFileClose(file));
134-
return cmdFileClose(file);
134+
return cmdFileClose2(file);
135135
}
136136

137137
err_t cmdFileReadAll(void* buf, size_t* count, const char* name)
@@ -161,7 +161,7 @@ err_t cmdFileReadAll(void* buf, size_t* count, const char* name)
161161
code = ERR_BAD_FILE;
162162
}
163163
ERR_CALL_HANDLE(code, cmdFileClose(file));
164-
return cmdFileClose(file);
164+
return cmdFileClose2(file);
165165
}
166166

167167
/*
@@ -210,7 +210,7 @@ err_t cmdFileBehead(const char* name, size_t count)
210210
code = ERR_FILE_WRITE;
211211
ERR_CALL_HANDLE(code, cmdFileClose(file));
212212
// завершить
213-
return cmdFileClose(file);
213+
return cmdFileClose2(file);
214214
}
215215

216216
err_t cmdFileDrop(const char* name, size_t count)
@@ -234,7 +234,7 @@ err_t cmdFileDrop(const char* name, size_t count)
234234
code = ERR_FILE_WRITE;
235235
ERR_CALL_HANDLE(code, cmdFileClose(file));
236236
// завершить
237-
return cmdFileClose(file);
237+
return cmdFileClose2(file);
238238
}
239239

240240
/*
@@ -292,9 +292,9 @@ err_t cmdFileDup(const char* oname, const char* iname, size_t skip,
292292
// завершить
293293
cmdBlobClose(buf);
294294
ERR_CALL_HANDLE(code, (cmdFileClose(ofile), cmdFileClose(ifile)));
295-
code = cmdFileClose(ofile);
295+
code = cmdFileClose2(ofile);
296296
ERR_CALL_HANDLE(code, cmdFileClose(ifile));
297-
return cmdFileClose(ifile);
297+
return cmdFileClose2(ifile);
298298
}
299299

300300
/*
@@ -314,7 +314,7 @@ err_t cmdFileValNotExist(int count, char* names[])
314314
code = cmdFileOpen(file, *names, "rb");
315315
if (code == ERR_OK)
316316
{
317-
code = cmdFileClose(file);
317+
code = cmdFileClose2(file);
318318
ERR_CALL_CHECK(code);
319319
if (printf("Some files already exist. Overwrite [y/n]?") < 0)
320320
return ERR_FILE_EXISTS;
@@ -340,7 +340,7 @@ err_t cmdFileValExist(int count, char* names[])
340340
code = cmdFileOpen(file, *names, "rb");
341341
if (code != ERR_OK)
342342
return ERR_FILE_NOT_FOUND;
343-
code = cmdFileClose(file);
343+
code = cmdFileClose2(file);
344344
ERR_CALL_CHECK(code);
345345
}
346346
return ERR_OK;
@@ -418,7 +418,7 @@ err_t cmdFilePrefixRead(octet* prefix, size_t* count, const char* name,
418418
code = ERR_FILE_READ;
419419
ERR_CALL_HANDLE(code, (cmdBlobClose(buf), cmdFileClose(file)));
420420
// закрыть файл
421-
code = cmdFileClose(file);
421+
code = cmdFileClose2(file);
422422
ERR_CALL_HANDLE(code, cmdBlobClose(buf));
423423
// проверить префикс
424424
if (!derIsValid3(buf, c))
@@ -488,7 +488,7 @@ err_t cmdFileSuffixRead(octet* suffix, size_t* count, const char* name,
488488
code = ERR_FILE_READ;
489489
ERR_CALL_HANDLE(code, (cmdBlobClose(buf), cmdFileClose(file)));
490490
// закрыть файл
491-
code = cmdFileClose(file);
491+
code = cmdFileClose2(file);
492492
ERR_CALL_HANDLE(code, cmdBlobClose(buf));
493493
// проверить суффикс
494494
memRev(buf, c);

cmd/core/cmd_sig.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Command-line interface to Bee2: signing files
55
\project bee2/cmd
66
\created 2022.08.20
7-
\version 2025.05.05
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -277,7 +277,7 @@ static err_t cmdSigHash(octet hash[], size_t hash_len, const char* name,
277277
bashHashStepH(stack, count, state);
278278
size -= count;
279279
}
280-
code = cmdFileClose(file);
280+
code = cmdFileClose2(file);
281281
ERR_CALL_HANDLE(code, cmdBlobClose(stack));
282282
// хэшировать сертификаты и дату
283283
if (hash_len <= 32)

cmd/core/cmd_st.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Command-line interface to Bee2: self-tests
55
\project bee2/cmd
66
\created 2025.04.09
7-
\version 2025.04.25
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -364,7 +364,7 @@ err_t cmdStCrc(octet crc[32], const char* prefix)
364364
beltHashStepH(buf, count, state);
365365
} while (count);
366366
// закрыть файл
367-
code = cmdFileClose(file);
367+
code = cmdFileClose2(file);
368368
ERR_CALL_HANDLE(code, cmdBlobClose(stack));
369369
// завершить
370370
beltHashStepG(crc, state);

cmd/core/cmd_stamp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Command-line interface to Bee2: file stamps
55
\project bee2/cmd
66
\created 2025.04.21
7-
\version 2025.04.25
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -109,7 +109,7 @@ static err_t cmdFileStamp(
109109
count -= c;
110110
}
111111
// закрыть файл
112-
code = cmdFileClose(file);
112+
code = cmdFileClose2(file);
113113
ERR_CALL_HANDLE(code, cmdBlobClose(stack));
114114
// завершить хэширование и кодировать
115115
bashHashStepG(stamp1, 8, state);

cmd/es/es.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Dealing with entropy sources
55
\project bee2/cmd
66
\created 2021.04.20
7-
\version 2025.05.07
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -206,7 +206,7 @@ static err_t esRead(int argc, char *argv[])
206206
count -= read;
207207
}
208208
// завершение
209-
return cmdFileClose(file);
209+
return cmdFileClose2(file);
210210
}
211211

212212
/*

include/bee2/core/file.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief File management
55
\project bee2 [cryptographic library]
66
\created 2025.04.11
7-
\version 2025.04.22
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -86,9 +86,18 @@ file_t fileTmp();
8686
/*! \brief Закрытие файла
8787
8888
Закрывается файл file.
89+
*/
90+
void fileClose(
91+
file_t file /*< [in,out] файл */
92+
);
93+
94+
/*! \brief Закрытие файла с контролем
95+
96+
Закрывается файл file. При закрытии контролируется завершение всех
97+
операций записи.
8998
\return Признак успеха.
9099
*/
91-
bool_t fileClose(
100+
bool_t fileClose2(
92101
file_t file /*< [in,out] файл */
93102
);
94103

src/core/file.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief File management
55
\project bee2 [cryptographic library]
66
\created 2025.04.11
7-
\version 2025.04.25
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -41,12 +41,17 @@ file_t fileTmp()
4141
return tmpfile();
4242
}
4343

44-
bool_t fileClose(file_t file)
44+
bool_t fileClose2(file_t file)
4545
{
4646
ASSERT(fileIsValid(file));
4747
return fclose(file) ? FALSE : TRUE;
4848
}
4949

50+
void fileClose(file_t file)
51+
{
52+
fileClose2(file);
53+
}
54+
5055
/*
5156
*******************************************************************************
5257
Файловый указатель

test/core/file_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\brief Tests for file management functions
55
\project bee2/test
66
\created 2025.04.13
7-
\version 2025.04.23
7+
\version 2025.05.27
88
\copyright The Bee2 authors
99
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
1010
*******************************************************************************
@@ -74,7 +74,7 @@ bool_t fileTest()
7474
return FALSE;
7575
}
7676
// закрыть файл
77-
if (!fileClose(file))
77+
if (!fileClose2(file))
7878
return FALSE;
7979
// все нормально
8080
return TRUE;

0 commit comments

Comments
 (0)