Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/iolog/iolog_seek.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2009-2021 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#include <config.h>
20
21
#include <stdio.h>
22
#include <time.h>
23
24
#include <sudo_compat.h>
25
#include <sudo_debug.h>
26
#include <sudo_iolog.h>
27
28
/*
29
* I/O log wrapper for fseek/gzseek.
30
*/
31
off_t
32
iolog_seek(struct iolog_file *iol, off_t offset, int whence)
33
{
34
off_t ret;
35
//debug_decl(iolog_seek, SUDO_DEBUG_UTIL);
36
37
#ifdef HAVE_ZLIB_H
38
if (iol->compressed)
39
ret = gzseek(iol->fd.g, offset, whence);
40
else
41
#endif
42
ret = fseeko(iol->fd.f, offset, whence);
43
44
//debug_return_off_t(ret);
45
return ret;
46
}
47
48
/*
49
* I/O log wrapper for rewind/gzrewind.
50
*/
51
void
52
iolog_rewind(struct iolog_file *iol)
53
{
54
debug_decl(iolog_rewind, SUDO_DEBUG_UTIL);
55
56
#ifdef HAVE_ZLIB_H
57
if (iol->compressed)
58
(void)gzrewind(iol->fd.g);
59
else
60
#endif
61
rewind(iol->fd.f);
62
63
debug_return;
64
}
65
66