Skip to content

Commit

Permalink
move Parrot_io_parse_open_flags from io/filehandle.c to io/api.c, TT …
Browse files Browse the repository at this point in the history
…#1639
  • Loading branch information
NotFound committed Dec 1, 2010
1 parent ff53eff commit bd48125
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 62 deletions.
16 changes: 8 additions & 8 deletions include/parrot/io.h
Expand Up @@ -237,6 +237,12 @@ PMC * Parrot_io_open(PARROT_INTERP,
ARGIN_NULLOK(STRING *mode))
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_parse_open_flags(PARROT_INTERP,
ARGIN_NULLOK(const STRING *mode_str))
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_peek(PARROT_INTERP,
Expand Down Expand Up @@ -382,6 +388,8 @@ PIOOFF_T Parrot_io_make_offset_pmc(PARROT_INTERP, ARGMOD(PMC *pmc))
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_io_open __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_io_parse_open_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_io_peek __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc) \
Expand Down Expand Up @@ -644,12 +652,6 @@ INTVAL Parrot_io_is_encoding(PARROT_INTERP,
__attribute__nonnull__(2)
__attribute__nonnull__(3);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_parse_open_flags(PARROT_INTERP,
ARGIN_NULLOK(const STRING *mode_str))
__attribute__nonnull__(1);

PARROT_EXPORT
void Parrot_io_set_file_position(SHIM_INTERP,
ARGMOD(PMC *filehandle),
Expand Down Expand Up @@ -759,8 +761,6 @@ void Parrot_io_set_buffer_start(SHIM_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(filehandle) \
, PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_Parrot_io_parse_open_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_io_set_file_position __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(filehandle))
#define ASSERT_ARGS_Parrot_io_set_file_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand Down
54 changes: 54 additions & 0 deletions src/io/api.c
Expand Up @@ -44,6 +44,60 @@ a new F<src/io/io_string.c>.
=over 4
=item C<INTVAL Parrot_io_parse_open_flags(PARROT_INTERP, const STRING
*mode_str)>
Parses a Parrot string for file open mode flags (C<r> for read, C<w> for write,
C<a> for append, and C<p> for pipe) and returns the combined generic bit flags.
=cut
*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_io_parse_open_flags(PARROT_INTERP, ARGIN_NULLOK(const STRING *mode_str))
{
ASSERT_ARGS(Parrot_io_parse_open_flags)
INTVAL i, mode_len;
INTVAL flags = 0;

if (STRING_IS_NULL(mode_str))
return PIO_F_READ;

mode_len = Parrot_str_byte_length(interp, mode_str);

for (i = 0; i < mode_len; ++i) {
const INTVAL s = STRING_ord(interp, mode_str, i);
switch (s) {
case 'r':
flags |= PIO_F_READ;
break;
case 'w':
flags |= PIO_F_WRITE;
if (!(flags & PIO_F_APPEND)) /* don't truncate if appending */
flags |= PIO_F_TRUNC;
break;
case 'a':
flags |= PIO_F_APPEND;
flags |= PIO_F_WRITE;
if ((flags & PIO_F_TRUNC)) /* don't truncate if appending */
flags &= ~PIO_F_TRUNC;
break;
case 'p':
flags |= PIO_F_PIPE;
break;
default:
break;
}
}

return flags;
}

/*
=item C<PMC * Parrot_io_stdhandle(PARROT_INTERP, INTVAL fileno, PMC *newhandle)>
Get the current standard IO object with the specified filenumber. If the
Expand Down
54 changes: 0 additions & 54 deletions src/io/filehandle.c
Expand Up @@ -26,60 +26,6 @@ operating systems. For the primary public I/O API, see F<src/io/api.c>.
=over 4
=item C<INTVAL Parrot_io_parse_open_flags(PARROT_INTERP, const STRING
*mode_str)>
Parses a Parrot string for file open mode flags (C<r> for read, C<w> for write,
C<a> for append, and C<p> for pipe) and returns the combined generic bit flags.
=cut
*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_io_parse_open_flags(PARROT_INTERP, ARGIN_NULLOK(const STRING *mode_str))
{
ASSERT_ARGS(Parrot_io_parse_open_flags)
INTVAL i, mode_len;
INTVAL flags = 0;

if (STRING_IS_NULL(mode_str))
return PIO_F_READ;

mode_len = Parrot_str_byte_length(interp, mode_str);

for (i = 0; i < mode_len; ++i) {
const INTVAL s = STRING_ord(interp, mode_str, i);
switch (s) {
case 'r':
flags |= PIO_F_READ;
break;
case 'w':
flags |= PIO_F_WRITE;
if (!(flags & PIO_F_APPEND)) /* don't truncate if appending */
flags |= PIO_F_TRUNC;
break;
case 'a':
flags |= PIO_F_APPEND;
flags |= PIO_F_WRITE;
if ((flags & PIO_F_TRUNC)) /* don't truncate if appending */
flags &= ~PIO_F_TRUNC;
break;
case 'p':
flags |= PIO_F_PIPE;
break;
default:
break;
}
}

return flags;
}

/*
=item C<STRING * Parrot_io_make_string(PARROT_INTERP, STRING **buf, size_t len)>
Creates a STRING* suitable for returning results from IO read functions.
Expand Down

0 comments on commit bd48125

Please sign in to comment.