Skip to content

Commit f6ee586

Browse files
committed
Update headers for Haiku OS compatibility.
Haiku OS defines "B_ERROR" as a macro, so I renamed the bstream_flags enum values to start with "BST_" instead of "B_", which should be slightly more memorable as well as not conflicting with BeOS errors. I also added #include <fcntl.h> to a common bash header file so that mkbuiltins.cc can find open() on Solaris 10.
1 parent 05bf0ad commit f6ee586

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

bashtypes.hh

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
#include <stdint.h>
3434
#endif
3535

36+
// Include and undefine the Gnulib macros that break (at least) Haiku OS.
37+
#include <stdlib.h>
38+
#ifdef strtoll
39+
#undef strtoll
40+
#endif
41+
#ifdef strtoull
42+
#undef strtoull
43+
#endif
44+
3645
// Undefine gnulib's static_assert macro from "assert.h",
3746
// which breaks the system C++ headers on MINIX and Solaris.
3847
#ifdef static_assert

error.cc

-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
#include "config.h"
2222

2323
#include <fcntl.h>
24-
25-
#if defined(HAVE_UNISTD_H)
2624
#include <unistd.h>
27-
#endif
2825

2926
#include <cstdarg>
3027

include/posixstat.hh

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#if !defined(_POSIXSTAT_H_)
2525
#define _POSIXSTAT_H_
2626

27+
#include <fcntl.h>
2728
#include <sys/stat.h>
2829

2930
#if defined(STAT_MACROS_BROKEN)

input.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ Shell::make_buffered_stream (int fd, char *buffer, size_t bufsize)
130130
bp->b_fd = fd;
131131
bp->b_buffer = buffer;
132132
bp->b_size = bufsize;
133-
bp->b_used = bp->b_inputp = bp->b_flag = B_NOFLAGS;
133+
bp->b_used = bp->b_inputp = bp->b_flag = BST_NOFLAGS;
134134
if (bufsize == 1)
135-
bp->b_flag |= B_UNBUFF;
135+
bp->b_flag |= BST_UNBUFF;
136136
if (O_TEXT && (::fcntl (fd, F_GETFL) & O_TEXT) != 0)
137-
bp->b_flag |= B_TEXT;
137+
bp->b_flag |= BST_TEXT;
138138
return bp;
139139
}
140140

@@ -172,7 +172,7 @@ Shell::save_bash_input (int fd, int new_fd)
172172
descriptor? Free up the buffer and report the error. */
173173
internal_error (
174174
_ ("save_bash_input: buffer already exists for new fd %d"), nfd);
175-
if (buffers[snfd]->b_flag & B_SHAREDBUF)
175+
if (buffers[snfd]->b_flag & BST_SHAREDBUF)
176176
buffers[snfd]->b_buffer = nullptr;
177177
free_buffered_stream (buffers[snfd]);
178178
}
@@ -256,7 +256,7 @@ Shell::duplicate_buffered_stream (int fd1, int fd2)
256256
&& buffers[sfd1]->b_buffer == buffers[sfd2]->b_buffer)
257257
buffers[sfd2] = nullptr;
258258
/* If this buffer is shared with another fd, don't free the buffer */
259-
else if (buffers[sfd2]->b_flag & B_SHAREDBUF)
259+
else if (buffers[sfd2]->b_flag & BST_SHAREDBUF)
260260
{
261261
buffers[sfd2]->b_buffer = nullptr;
262262
free_buffered_stream (buffers[sfd2]);
@@ -272,12 +272,12 @@ Shell::duplicate_buffered_stream (int fd1, int fd2)
272272
{
273273
if (!buffers[sfd2])
274274
fd_to_buffered_stream (fd2);
275-
buffers[sfd2]->b_flag |= B_WASBASHINPUT;
275+
buffers[sfd2]->b_flag |= BST_WASBASHINPUT;
276276
}
277277

278278
if (fd_is_bash_input (fd1)
279-
|| (buffers[sfd1] && (buffers[sfd1]->b_flag & B_SHAREDBUF)))
280-
buffers[sfd2]->b_flag |= B_SHAREDBUF;
279+
|| (buffers[sfd1] && (buffers[sfd1]->b_flag & BST_SHAREDBUF)))
280+
buffers[sfd2]->b_flag |= BST_SHAREDBUF;
281281

282282
return fd2;
283283
}
@@ -323,14 +323,14 @@ Shell::b_fill_buffer (BUFFERED_STREAM *bp)
323323
compensate for lseek() on text files returning an offset different from
324324
the count of characters read() returns. Text-mode streams have to be
325325
treated as unbuffered. */
326-
if ((bp->b_flag & (B_TEXT | B_UNBUFF)) == B_TEXT)
326+
if ((bp->b_flag & (BST_TEXT | BST_UNBUFF)) == BST_TEXT)
327327
{
328328
o = lseek (bp->b_fd, 0, SEEK_CUR);
329329
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
330330
if (nr > 0 && nr < lseek (bp->b_fd, 0, SEEK_CUR) - o)
331331
{
332332
lseek (bp->b_fd, o, SEEK_SET);
333-
bp->b_flag |= B_UNBUFF;
333+
bp->b_flag |= BST_UNBUFF;
334334
bp->b_size = 1;
335335
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
336336
}
@@ -342,9 +342,9 @@ Shell::b_fill_buffer (BUFFERED_STREAM *bp)
342342
bp->b_used = bp->b_inputp = 0;
343343
bp->b_buffer[0] = 0;
344344
if (nr == 0)
345-
bp->b_flag |= B_EOF;
345+
bp->b_flag |= BST_EOF;
346346
else
347-
bp->b_flag |= B_ERROR;
347+
bp->b_flag |= BST_ERROR;
348348
return EOF;
349349
}
350350

input.hh

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ enum stream_type
4242
/* Possible values for b_flag. */
4343
enum bstream_flags
4444
{
45-
B_NOFLAGS = 0,
46-
B_EOF = 0x01,
47-
B_ERROR = 0x02,
48-
B_UNBUFF = 0x04,
49-
B_WASBASHINPUT = 0x08,
50-
B_TEXT = 0x10,
51-
B_SHAREDBUF = 0x20 /* shared input buffer */
45+
BST_NOFLAGS = 0,
46+
BST_EOF = 0x01,
47+
BST_ERROR = 0x02,
48+
BST_UNBUFF = 0x04,
49+
BST_WASBASHINPUT = 0x08,
50+
BST_TEXT = 0x10,
51+
BST_SHAREDBUF = 0x20 /* shared input buffer */
5252
};
5353

5454
static inline bstream_flags &

shell.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2987,7 +2987,7 @@ protected:
29872987
return 0;
29882988

29892989
int fd = bp->b_fd;
2990-
if (bp->b_flag & B_SHAREDBUF)
2990+
if (bp->b_flag & BST_SHAREDBUF)
29912991
bp->b_buffer = nullptr;
29922992
free_buffered_stream (bp);
29932993
return close (fd);

0 commit comments

Comments
 (0)