File: files.pyx

package info (click to toggle)
pythontracer 8.10.16-1.2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 352 kB
  • ctags: 461
  • sloc: python: 441; ansic: 325; makefile: 9
file content (20 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cimport posix

cdef int safe_fflush(FILE *stream) except -1:
    if -1 == posix.fflush(stream):
        raise OSError(posix.errno, "fflush")
    return 0

cdef size_t safe_fread(void *ptr, size_t size, FILE *stream) except -1:
    cdef int rc
    rc = posix.fread(ptr, 1, size, stream)
    if rc == -1:
        raise OSError(posix.errno, "fread")
    return rc

cdef size_t safe_fwrite(void *ptr, size_t size, FILE *stream) except -1:
    cdef int rc
    rc = posix.fwrite(ptr, 1, size, stream)
    if rc == -1:
        raise OSError(posix.errno, "fwrite")
    return rc