Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Мотыгуллин Амир Булатович
libakrypt-motygullin-pcdch
Commits
9d719b10
Commit
9d719b10
authored
5 months ago
by
Нестеренко Алексей Юрьевич
Browse files
Options
Download
Patches
Plain Diff
Добавлена функция ak_file_lseek()
parent
227fff4e
master
0.9.16
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CMakeLists.txt
+1
-0
CMakeLists.txt
Changelog.md
+1
-0
Changelog.md
examples/akbase/example-file-seek.c
+27
-0
examples/akbase/example-file-seek.c
source/ak_file.c
+30
-0
source/ak_file.c
source/libakrypt-base.h.in
+19
-0
source/libakrypt-base.h.in
with
78 additions
and
0 deletions
+78
-0
CMakeLists.txt
+
1
−
0
View file @
9d719b10
...
...
@@ -214,6 +214,7 @@ set( BASE_EXAMPLES_LIST
ini
ini-file
file
file-seek
mmap
realpath
htable
...
...
This diff is collapsed.
Click to expand it.
Changelog.md
+
1
−
0
View file @
9d719b10
...
...
@@ -5,6 +5,7 @@
-
исправлены некоторые ошибки при контроле целостности процессов в памяти
для 32х битных архитектур
-
добавлена функция ak_file_lseek()
-
изменения в утилите aktool icode
-
опция -o, --output заменена на опцию -d, --database
-
добавлена опция --exclude-link
...
...
This diff is collapsed.
Click to expand it.
examples/akbase/example-file-seek.c
0 → 100644
+
27
−
0
View file @
9d719b10
#include
<stdio.h>
#include
<libakrypt-base.h>
int
main
(
void
)
{
struct
file
fs
;
ak_uint8
buffer
[
16
]
=
{
0x0
,
0x1
,
0x2
,
0x3
,
0x4
,
0x5
,
0x6
,
0x7
,
0x8
,
0x9
,
0xa
,
0xb
,
0xc
,
0xd
,
0xe
,
0xf
};
/* создаем файл */
ak_file_create_to_write
(
&
fs
,
"hello.seek"
);
ak_file_write
(
&
fs
,
buffer
,
sizeof
(
buffer
));
ak_file_close
(
&
fs
);
/* теперь считываем в обратном порядке, используя lseek */
ak_file_open_to_read
(
&
fs
,
"hello.seek"
);
for
(
int
offset
=
15
;
offset
>=
0
;
offset
--
)
{
ak_file_lseek
(
&
fs
,
offset
,
SEEK_SET
);
ak_file_read
(
&
fs
,
buffer
,
1
);
printf
(
"%02x "
,
buffer
[
0
]
);
}
printf
(
"
\n
"
);
ak_file_close
(
&
fs
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
source/ak_file.c
+
30
−
0
View file @
9d719b10
...
...
@@ -398,6 +398,36 @@
#endif
}
/* ----------------------------------------------------------------------------------------------- */
/*! @param file указатель на контекст файла
@param offset размер сдвига (в октетах)
@param whence указатель на то, откуда отмеряется сдвиг
- SEEK_SET сдинуть указатель с начала файла
- SEEK_CUR сдвинуть указатель с текущего места
- SEEK_END сдвинуть указатель с конца файла
@return В случае успеха в качестве результата возвращается результирующий сдвиг от начала файла,
в случае ошибки возвращается -1. */
/* ----------------------------------------------------------------------------------------------- */
ak_int64
ak_file_lseek
(
ak_file
file
,
ak_int64
offset
,
int
whence
)
{
#ifdef AK_HAVE_WINDOWS_H
/* пока обрабатываем только небольшие файлы */
ak_int64
wb
=
SetFilePointer
(
file
->
hFile
,
(
ak_uint32
)
offset
,
NULL
,
whence
);
if
(
wb
==
INVALID_SET_FILE_POINTER
)
{
ak_error_message
(
ak_error_lseek_file
,
__func__
,
"unable to seek file"
);
return
-
1
;
}
else
return
wb
;
#else
ak_int64
wb
=
lseek
(
file
->
fd
,
(
off_t
)
offset
,
whence
);
if
(
wb
==
-
1
)
ak_error_message_fmt
(
ak_error_lseek_file
,
__func__
,
"unable to seek file (%s)"
,
strerror
(
errno
));
return
wb
;
#endif
}
/* ----------------------------------------------------------------------------------------------- */
ssize_t
ak_file_printf
(
ak_file
outfile
,
const
char
*
format
,
...
)
{
...
...
This diff is collapsed.
Click to expand it.
source/libakrypt-base.h.in
+
19
−
0
View file @
9d719b10
...
...
@@ -263,6 +263,8 @@ extern "C" {
#define ak_error_mmap_file (-25)
/*! \brief Ошибка удаления файла из памяти */
#define ak_error_unmap_file (-26)
/*! \brief Ошибка сдвига файлового указателя */
#define ak_error_lseek_file (-27)
/*! \brief Ошибка выполнения библиотеки на неверной архитектуре. */
#define ak_error_wrong_endian (-31)
...
...
@@ -584,6 +586,8 @@ extern "C" {
dll_export ssize_t ak_file_read( ak_file , ak_pointer , size_t );
/*! \brief Функция записывает заданное количество байт в файл. */
dll_export ssize_t ak_file_write( ak_file , ak_const_pointer , size_t );
/*! \brief Функция сдвигает файловый указатель на заданное количество байт. */
dll_export ak_int64 ak_file_lseek( ak_file , ak_int64 , int );
/*! \brief Функция записывает в файл строку символов. */
dll_export ssize_t ak_file_printf( ak_file , const char * , ... );
/*! \brief Отображение заданного файла в память. */
...
...
@@ -602,6 +606,21 @@ extern "C" {
dll_export int ak_realpath( const char * , char * , size_t );
/*! \brief Функция получает домашний каталог пользователя. */
dll_export int ak_homepath( char * , const size_t );
/* ----------------------------------------------------------------------------------------------- */
/* дообпределяем макросы для функции ak_file_lseek */
#ifdef AK_HAVE_WINDOWS_H
#ifndef SEEK_SET
#define SEEK_SET FILE_BEGIN
#endif
#ifndef SEEK_CUR
#define SEEK_CUR FILE_CURRENT
#endif
#ifndef SEEK_END
#define SEEK_END FILE_END
#endif
#endif
/** @} */
/* ----------------------------------------------------------------------------------------------- */
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets