Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 pmbaty 1
/* ACC -- Automatic Compiler Configuration
2
 
3
   Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
4
   All Rights Reserved.
5
 
6
   This software is a copyrighted work licensed under the terms of
7
   the GNU General Public License. Please consult the file "ACC_LICENSE"
8
   for details.
9
 
10
   Markus F.X.J. Oberhumer
11
   <markus@oberhumer.com>
12
   http://www.oberhumer.com/
13
 */
14
 
15
 
16
#define __ACCLIB_HSREAD_CH_INCLUDED 1
17
#if !defined(ACCLIB_PUBLIC)
18
#  define ACCLIB_PUBLIC(r,f)    r __ACCLIB_FUNCNAME(f)
19
#endif
20
 
21
 
22
/***********************************************************************
23
// huge pointer layer - safe read/write
24
// handles partial pipe writes and interrupted system calls
25
************************************************************************/
26
 
27
ACCLIB_PUBLIC(long, acc_safe_hread) (int fd, acc_hvoid_p buf, long size)
28
{
29
    acc_hbyte_p b = (acc_hbyte_p) buf;
30
    long l = 0;
31
    int saved_errno;
32
 
33
    saved_errno = errno;
34
    while (l < size)
35
    {
36
        long n = size - l;
37
#if (ACC_HAVE_MM_HUGE_PTR)
38
#  define __ACCLIB_REQUIRE_HREAD_CH 1
39
        errno = 0; n = acc_hread(fd, b, n);
40
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
41
        errno = 0; n = _read(fd, b, n);
42
#else
43
        errno = 0; n = read(fd, b, n);
44
#endif
45
        if (n == 0)
46
            break;
47
        if (n < 0) {
48
#if defined(EINTR)
49
            if (errno == (EINTR)) continue;
50
#endif
51
            if (errno == 0) errno = 1;
52
            return l;
53
        }
54
        b += n; l += n;
55
    }
56
    errno = saved_errno;
57
    return l;
58
}
59
 
60
 
61
ACCLIB_PUBLIC(long, acc_safe_hwrite) (int fd, const acc_hvoid_p buf, long size)
62
{
63
    const acc_hbyte_p b = (const acc_hbyte_p) buf;
64
    long l = 0;
65
    int saved_errno;
66
 
67
    saved_errno = errno;
68
    while (l < size)
69
    {
70
        long n = size - l;
71
#if (ACC_HAVE_MM_HUGE_PTR)
72
#  define __ACCLIB_REQUIRE_HREAD_CH 1
73
        errno = 0; n = acc_hwrite(fd, b, n);
74
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
75
        errno = 0; n = _write(fd, b, n);
76
#else
77
        errno = 0; n = write(fd, b, n);
78
#endif
79
        if (n == 0)
80
            break;
81
        if (n < 0) {
82
#if defined(EINTR)
83
            if (errno == (EINTR)) continue;
84
#endif
85
            if (errno == 0) errno = 1;
86
            return l;
87
        }
88
        b += n; l += n;
89
    }
90
    errno = saved_errno;
91
    return l;
92
}
93
 
94
 
95
/*
96
vi:ts=4:et
97
*/