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_MISC_CH_INCLUDED 1
17
#if !defined(ACCLIB_PUBLIC)
18
#  define ACCLIB_PUBLIC(r,f)    r __ACCLIB_FUNCNAME(f)
19
#endif
20
 
21
 
22
/*************************************************************************
23
// wrap misc
24
**************************************************************************/
25
 
26
ACCLIB_PUBLIC(acclib_handle_t, acc_get_osfhandle) (int fd)
27
{
28
    if (fd < 0)
29
        return -1;
30
#if (ACC_OS_CYGWIN)
31
    return get_osfhandle(fd);
32
#elif (ACC_OS_EMX && defined(__RSXNT__))
33
    return -1; /* FIXME */
34
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
35
    return -1; /* FIXME */
36
#elif (ACC_OS_WIN32 || ACC_OS_WIN64)
37
# if (ACC_CC_PELLESC && (__POCC__ < 280))
38
    return -1; /* FIXME */
39
# elif (ACC_CC_WATCOMC && (__WATCOMC__ < 1000))
40
    return -1; /* FIXME */
41
# elif (ACC_CC_WATCOMC && (__WATCOMC__ < 1100))
42
    return _os_handle(fd);
43
# else
44
    return _get_osfhandle(fd);
45
# endif
46
#else
47
    return fd;
48
#endif
49
}
50
 
51
 
52
ACCLIB_PUBLIC(int, acc_set_binmode) (int fd, int binary)
53
{
54
#if (ACC_OS_TOS && defined(__MINT__))
55
    FILE* fp; int old_binary;
56
    if (fd == STDIN_FILENO) fp = stdin;
57
    else if (fd == STDOUT_FILENO) fp = stdout;
58
    else if (fd == STDERR_FILENO) fp = stderr;
59
    else return -1;
60
    old_binary = fp->__mode.__binary;
61
    __set_binmode(fp, binary ? 1 : 0);
62
    return old_binary ? 1 : 0;
63
#elif (ACC_OS_TOS)
64
    ACC_UNUSED(fd); ACC_UNUSED(binary);
65
    return -1; /* FIXME */
66
#elif (ACC_OS_DOS16 && (ACC_CC_AZTECC || ACC_CC_PACIFICC))
67
    ACC_UNUSED(fd); ACC_UNUSED(binary);
68
    return -1; /* FIXME */
69
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
70
    int r; unsigned old_flags = __djgpp_hwint_flags;
71
    ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
72
    ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
73
    if (fd < 0) return -1;
74
    r = setmode(fd, binary ? O_BINARY : O_TEXT);
75
    if ((old_flags & 1u) != (__djgpp_hwint_flags & 1u))
76
        __djgpp_set_ctrl_c(!(old_flags & 1));
77
    if (r == -1) return -1;
78
    return (r & O_TEXT) ? 0 : 1;
79
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
80
    if (fd < 0) return -1;
81
    ACC_UNUSED(binary);
82
    return 1;
83
#elif (ACC_OS_DOS32 && ACC_CC_HIGHC)
84
    FILE* fp; int r;
85
    if (fd == fileno(stdin)) fp = stdin;
86
    else if (fd == fileno(stdout)) fp = stdout;
87
    else if (fd == fileno(stderr)) fp = stderr;
88
    else return -1;
89
    r = _setmode(fp, binary ? _BINARY : _TEXT);
90
    if (r == -1) return -1;
91
    return (r & _BINARY) ? 1 : 0;
92
#elif (ACC_OS_WIN32 && ACC_CC_MWERKS) && defined(__MSL__)
93
    ACC_UNUSED(fd); ACC_UNUSED(binary);
94
    return -1; /* FIXME */
95
#elif (ACC_OS_CYGWIN && (ACC_CC_GNUC < 0x025a00ul))
96
    ACC_UNUSED(fd); ACC_UNUSED(binary);
97
    return -1; /* FIXME */
98
#elif (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
99
    int r;
100
#if !defined(ACC_CC_ZORTECHC)
101
    ACC_COMPILE_TIME_ASSERT(O_BINARY > 0)
102
#endif
103
    ACC_COMPILE_TIME_ASSERT(O_TEXT > 0)
104
    if (fd < 0) return -1;
105
    r = setmode(fd, binary ? O_BINARY : O_TEXT);
106
    if (r == -1) return -1;
107
    return (r & O_TEXT) ? 0 : 1;
108
#else
109
    if (fd < 0) return -1;
110
    ACC_UNUSED(binary);
111
    return 1;
112
#endif
113
}
114
 
115
 
116
ACCLIB_PUBLIC(int, acc_isatty) (int fd)
117
{
118
    /* work around library implementations that think that
119
     * any character device like `nul' is a tty */
120
    if (fd < 0)
121
        return 0;
122
#if (ACC_OS_DOS16 && !defined(ACC_CC_AZTECC))
123
    {
124
        union REGS ri, ro;
125
        ri.x.ax = 0x4400; ri.x.bx = fd;
126
        int86(0x21, &ri, &ro);
127
        if ((ro.x.cflag & 1) == 0)  /* if carry flag not set */
128
            if ((ro.x.ax & 0x83) != 0x83)
129
                return 0;
130
    }
131
#elif (ACC_OS_DOS32 && ACC_CC_WATCOMC)
132
    {
133
        union REGS ri, ro;
134
        ri.w.ax = 0x4400; ri.w.bx = (unsigned short) fd;
135
        int386(0x21, &ri, &ro);
136
        if ((ro.w.cflag & 1) == 0)  /* if carry flag not set */
137
            if ((ro.w.ax & 0x83) != 0x83)
138
                return 0;
139
    }
140
#elif (ACC_HAVE_WINDOWS_H)
141
    {
142
        acclib_handle_t h = __ACCLIB_FUNCNAME(acc_get_osfhandle)(fd);
143
        if ((HANDLE)h != INVALID_HANDLE_VALUE)
144
        {
145
            DWORD d = 0;
146
            if (GetConsoleMode((HANDLE)h, &d) == 0)
147
                return 0;   /* GetConsoleMode failed -> not a tty */
148
        }
149
    }
150
#endif
151
    return (isatty(fd)) ? 1 : 0;
152
}
153
 
154
 
155
ACCLIB_PUBLIC(int, acc_mkdir) (const char* name, unsigned mode)
156
{
157
#if (ACC_OS_TOS && (ACC_CC_PUREC || ACC_CC_TURBOC))
158
    ACC_UNUSED(mode);
159
    return Dcreate(name);
160
#elif (ACC_OS_DOS32 && ACC_CC_GNUC) && defined(__DJGPP__)
161
    return mkdir(name, mode);
162
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__PW32__)
163
    return mkdir(name, mode);
164
#elif (ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
165
    ACC_UNUSED(mode);
166
# if (ACC_CC_HIGHC || ACC_CC_PACIFICC)
167
    return mkdir((char*) name);
168
# else
169
    return mkdir(name);
170
# endif
171
#else
172
    return mkdir(name, mode);
173
#endif
174
}
175
 
176
 
177
ACCLIB_PUBLIC(acc_int32l_t, acc_muldiv32) (acc_int32l_t a, acc_int32l_t b, acc_int32l_t x)
178
{
179
    acc_int32l_t r = 0;
180
    if (x == 0) return x;
181
    /* FIXME */
182
    ACC_UNUSED(a); ACC_UNUSED(b);
183
    return r;
184
}
185
 
186
 
187
ACCLIB_PUBLIC(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t a, acc_uint32l_t b, acc_uint32l_t x)
188
{
189
    acc_uint32l_t r = 0;
190
    if (x == 0) return x;
191
    /* FIXME */
192
    ACC_UNUSED(a); ACC_UNUSED(b);
193
    return r;
194
}
195
 
196
 
197
/*
198
vi:ts=4:et
199
*/