mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 06:03:35 +08:00
Disable line buffering if the file is opened in binary mode; Also fix a couple of fopen/fdopen bugs
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4630 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -2663,4 +2663,11 @@
|
|||||||
initial check-in is just a stm3210e-eval driver with renaming).
|
initial check-in is just a stm3210e-eval driver with renaming).
|
||||||
* sched/sched_setscheduler.c: Correct successful return value (Contributed
|
* sched/sched_setscheduler.c: Correct successful return value (Contributed
|
||||||
by Richard Cochran).
|
by Richard Cochran).
|
||||||
|
* include/fcntl.h and lib/stdio: Ignore CONFIG_STDIO_LINEBUFFER is the
|
||||||
|
file was opened in binary mode.
|
||||||
|
* lib/stdio/lib_fopen.c: Correct an error in parsing open mode string. The
|
||||||
|
plus sign may not appear right after the basic mode. For example, "r+", "rb+",
|
||||||
|
and "r+b" are all value open strings and mean the same thing.
|
||||||
|
* lib/stdio/lib_fopen.c: Correct return errno value from f_open() and
|
||||||
|
f_fdopen() if the open mode string is invalid.
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
stream->fs_filedes = fd;
|
stream->fs_filedes = fd;
|
||||||
stream->fs_oflags = oflags;
|
stream->fs_oflags = (uint16_t)oflags;
|
||||||
|
|
||||||
sem_post(&slist->sl_sem);
|
sem_post(&slist->sl_sem);
|
||||||
return stream;
|
return stream;
|
||||||
|
|||||||
+27
-18
@@ -1,8 +1,8 @@
|
|||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* include/fcntl.h
|
* include/fcntl.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -51,24 +51,33 @@
|
|||||||
|
|
||||||
/* open flag settings for open() (and related APIs) */
|
/* open flag settings for open() (and related APIs) */
|
||||||
|
|
||||||
#define O_RDONLY 0x01 /* Open for read access */
|
#define O_RDONLY (1 << 0) /* Open for read access (only) */
|
||||||
#define O_WRONLY 0x02 /* Open for write access */
|
#define O_RDOK O_RDONLY /* Read access is permitted (non-standard) */
|
||||||
#define O_RDWR 0x03 /* Open for both read & write access */
|
#define O_WRONLY (1 << 1) /* Open for write access (only) */
|
||||||
#define O_CREAT 0x04 /* Create file/sem/mq object */
|
#define O_WROK O_WRONLY /* Write access is permitted (non-standard) */
|
||||||
#define O_EXCL 0x08 /* Name must not exist when opened */
|
#define O_RDWR (O_RDOK|O_WROK) /* Open for both read & write access */
|
||||||
#define O_APPEND 0x10 /* Keep contents, append to end */
|
#define O_CREAT (1 << 2) /* Create file/sem/mq object */
|
||||||
#define O_TRUNC 0x20 /* Delete contents */
|
#define O_EXCL (1 << 3) /* Name must not exist when opened */
|
||||||
#define O_NONBLOCK 0x40 /* Don't wait for data */
|
#define O_APPEND (1 << 4) /* Keep contents, append to end */
|
||||||
#define O_NDELAY O_NONBLOCK
|
#define O_TRUNC (1 << 5) /* Delete contents */
|
||||||
#define O_SYNC 0x80 /* Synchronize output on write */
|
#define O_NONBLOCK (1 << 6) /* Don't wait for data */
|
||||||
#define O_DSYNC O_SYNC
|
#define O_NDELAY O_NONBLOCK /* Synonym for O_NONBLOCK */
|
||||||
|
#define O_SYNC (1 << 7) /* Synchronize output on write */
|
||||||
|
#define O_DSYNC O_SYNC /* Equivalent to OSYNC in NuttX */
|
||||||
|
#define O_BINARY (1 << 8) /* Open the file in binary (untranslated) mode. */
|
||||||
|
|
||||||
#define O_RSYNC 0x00 /* Sychronize input on read */
|
/* Unsupported, but required open flags */
|
||||||
#define O_ACCMODE 0x00 /* Required by POSIX */
|
|
||||||
#define O_NOCTTY 0x00 /* Reqired by POSIX */
|
|
||||||
|
|
||||||
#define O_RDOK O_RDONLY /* Not POSIX */
|
#define O_RSYNC 0 /* Synchronize input on read */
|
||||||
#define O_WROK O_WRONLY /* Not POSIX */
|
#define O_ACCMODE 0 /* Required by POSIX */
|
||||||
|
#define O_NOCTTY 0 /* Required by POSIX */
|
||||||
|
#defone O_TEXT 0 /* Open the file in text (translated) mode. */
|
||||||
|
|
||||||
|
/* This is the highest bit number used in the open flags bitset. Bits above
|
||||||
|
* this bit number may be used within NuttX for other, internal purposes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _O_MAXBIT 8
|
||||||
|
|
||||||
/* fcntl() commands */
|
/* fcntl() commands */
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ struct filelist
|
|||||||
struct file_struct
|
struct file_struct
|
||||||
{
|
{
|
||||||
int fs_filedes; /* File descriptor associated with stream */
|
int fs_filedes; /* File descriptor associated with stream */
|
||||||
mode_t fs_oflags; /* Open mode flags */
|
uint16_t fs_oflags; /* Open mode flags */
|
||||||
#if CONFIG_NUNGET_CHARS > 0
|
#if CONFIG_NUNGET_CHARS > 0
|
||||||
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
|
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
|
||||||
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
|
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* include/sys/stat.h
|
* include/sys/stat.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -47,10 +47,9 @@
|
|||||||
* Definitions
|
* Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* mode_t bit settings (most of these do not apply to Nuttx).
|
/* mode_t bit settings (most of these do not apply to Nuttx). This assumes
|
||||||
* This assumes that the full size of a mode_t is 16-bits.
|
* that the full size of a mode_t is 16-bits. (However, mode_t must be size
|
||||||
* (However, mode_t must be size 'int' because it is promoted
|
* 'int' because it is promoted to size int when passed in varargs).
|
||||||
* to size int when passed in varargs).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define S_IXOTH 0000001 /* Permissions for others: RWX */
|
#define S_IXOTH 0000001 /* Permissions for others: RWX */
|
||||||
|
|||||||
@@ -53,6 +53,11 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
/* This configuration directory is used in environment variable processing
|
||||||
|
* when we need to reference the user's home directory. There are no user
|
||||||
|
* directories in NuttX so, by default, this always refers to the root
|
||||||
|
* directory.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef CONFIG_LIB_HOMEDIR
|
#ifndef CONFIG_LIB_HOMEDIR
|
||||||
# define CONFIG_LIB_HOMEDIR "/"
|
# define CONFIG_LIB_HOMEDIR "/"
|
||||||
|
|||||||
+175
-56
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_fopen.c
|
* lib/stdio/lib_fopen.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -48,6 +48,25 @@
|
|||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
enum open_mode_e
|
||||||
|
{
|
||||||
|
MODE_NONE = 0, /* No access mode determined */
|
||||||
|
MODE_R, /* "r" or "rb" open for reading */
|
||||||
|
MODE_W, /* "w" or "wb" open for writing, truncating or creating file */
|
||||||
|
MODE_A, /* "a" or "ab" open for writing, appending to file */
|
||||||
|
MODE_RPLUS, /* "r+", "rb+", or "r+b" open for update (reading and writing) */
|
||||||
|
MODE_WPLUS, /* "w+", "wb+", or "w+b" open for update, truncating or creating file */
|
||||||
|
MODE_APLUS, /* "a+", "ab+", or "a+b" open for update, appending to file */
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -58,77 +77,159 @@
|
|||||||
|
|
||||||
static int lib_mode2oflags(FAR const char *mode)
|
static int lib_mode2oflags(FAR const char *mode)
|
||||||
{
|
{
|
||||||
int oflags = 0;
|
enum open_mode_e state;
|
||||||
if (mode)
|
int oflags;
|
||||||
|
|
||||||
|
/* Verify that a mode string was provided. No error is */
|
||||||
|
|
||||||
|
if (!mode)
|
||||||
{
|
{
|
||||||
while(*mode)
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse the mode string to determine the corresponding open flags */
|
||||||
|
|
||||||
|
state = MODE_NONE;
|
||||||
|
oflags = 0;
|
||||||
|
|
||||||
|
for (; *mode; mode++)
|
||||||
|
{
|
||||||
|
switch (*mode)
|
||||||
{
|
{
|
||||||
switch (*mode)
|
/* Open for read access ("r", "r[+]", "r[b]", "r[b+]", or "r[+b]") */
|
||||||
{
|
|
||||||
/* Open for read access */
|
|
||||||
|
|
||||||
case 'r' :
|
case 'r' :
|
||||||
if (*(mode + 1) == '+')
|
if (state == MODE_NONE)
|
||||||
{
|
{
|
||||||
/* Open for read/write access */
|
/* Open for read access */
|
||||||
|
|
||||||
oflags |= O_RDWR;
|
oflags = O_RDOK;
|
||||||
mode++;
|
state = MODE_R;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Open for write access ("w", "w[+]", "w[b]", "w[b+]", or "w[+b]") */
|
||||||
|
|
||||||
|
case 'w' :
|
||||||
|
if (state == MODE_NONE)
|
||||||
|
{
|
||||||
|
/* Open for write access, truncating any existing file */
|
||||||
|
|
||||||
|
oflags = O_WROK|O_CREAT|O_TRUNC;
|
||||||
|
state = MODE_W;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Open for write/append access ("a", "a[+]", "a[b]", "a[b+]", or "a[+b]") */
|
||||||
|
|
||||||
|
case 'a' :
|
||||||
|
if (state == MODE_NONE)
|
||||||
|
{
|
||||||
|
/* Write to the end of the file */
|
||||||
|
|
||||||
|
oflags = O_WROK|O_CREAT|O_APPEND;
|
||||||
|
state = MODE_A;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Open for update access ("[r]+", "[rb]+]", "[r]+[b]", "[w]+",
|
||||||
|
* "[wb]+]", "[w]+[b]", "[a]+", "[ab]+]", "[a]+[b]")
|
||||||
|
*/
|
||||||
|
|
||||||
|
case '+' :
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case MODE_R:
|
||||||
|
{
|
||||||
|
/* Retain any binary mode selection */
|
||||||
|
|
||||||
|
oflags &= O_BINARY;
|
||||||
|
|
||||||
|
/* Open for read/write access */
|
||||||
|
|
||||||
|
oflags |= O_RDWR;
|
||||||
|
state = MODE_RPLUS;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
/* Open for read access */
|
|
||||||
|
|
||||||
oflags |= O_RDOK;
|
case MODE_W:
|
||||||
}
|
{
|
||||||
break;
|
/* Retain any binary mode selection */
|
||||||
|
|
||||||
/* Open for write access? */
|
oflags &= O_BINARY;
|
||||||
|
|
||||||
case 'w' :
|
/* Open for write read/access, truncating any existing file */
|
||||||
if (*(mode + 1) == '+')
|
|
||||||
{
|
|
||||||
/* Open for write read/access, truncating any existing file */
|
|
||||||
|
|
||||||
oflags |= O_RDWR|O_CREAT|O_TRUNC;
|
oflags |= O_RDWR|O_CREAT|O_TRUNC;
|
||||||
mode++;
|
state = MODE_WPLUS;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
/* Open for write access, truncating any existing file */
|
|
||||||
|
|
||||||
oflags |= O_WROK|O_CREAT|O_TRUNC;
|
case MODE_A:
|
||||||
}
|
{
|
||||||
break;
|
/* Retain any binary mode selection */
|
||||||
|
|
||||||
/* Open for write/append access? */
|
oflags &= O_BINARY;
|
||||||
|
|
||||||
case 'a' :
|
/* Read from the beginning of the file; write to the end */
|
||||||
if (*(mode + 1) == '+')
|
|
||||||
{
|
|
||||||
/* Read from the beginning of the file; write to the end */
|
|
||||||
|
|
||||||
oflags |= O_RDWR|O_CREAT|O_APPEND;
|
oflags |= O_RDWR|O_CREAT|O_APPEND;
|
||||||
mode++;
|
state = MODE_APLUS;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
/* Write to the end of the file */
|
|
||||||
|
|
||||||
oflags |= O_WROK|O_CREAT|O_APPEND;
|
default:
|
||||||
}
|
goto errout;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
/* Open for binary access? */
|
/* Open for binary access ("[r]b", "[r]b[+]", "[r+]b", "[w]b",
|
||||||
|
* "[w]b[+]", "[w+]b", "[a]b", "[a]b[+]", "[a+]b")
|
||||||
|
*/
|
||||||
|
|
||||||
case 'b' :
|
case 'b' :
|
||||||
default:
|
if (state != MODE_NONE)
|
||||||
break;
|
{
|
||||||
}
|
/* The file is opened in binary mode */
|
||||||
mode++;
|
|
||||||
|
oflags |= O_BINARY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Unrecognized or unsupported mode */
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto errout;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return oflags;
|
return oflags;
|
||||||
|
|
||||||
|
/* Both fopen and fdopen should fail with errno == EINVAL if the mode
|
||||||
|
* string is invalid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
errout:
|
||||||
|
set_errno(EINVAL);
|
||||||
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -141,7 +242,18 @@ static int lib_mode2oflags(FAR const char *mode)
|
|||||||
|
|
||||||
FAR FILE *fdopen(int fd, FAR const char *mode)
|
FAR FILE *fdopen(int fd, FAR const char *mode)
|
||||||
{
|
{
|
||||||
return fs_fdopen(fd, lib_mode2oflags(mode), NULL);
|
FAR FILE *ret = NULL;
|
||||||
|
int oflags;
|
||||||
|
|
||||||
|
/* Map the open mode string to open flags */
|
||||||
|
|
||||||
|
oflags = lib_mode2oflags(mode);
|
||||||
|
if (oflags >= 0)
|
||||||
|
{
|
||||||
|
ret = fs_fdopen(fd, oflags, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -154,9 +266,16 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode)
|
|||||||
int oflags;
|
int oflags;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Open the file */
|
/* Map the open mode string to open flags */
|
||||||
|
|
||||||
oflags = lib_mode2oflags(mode);
|
oflags = lib_mode2oflags(mode);
|
||||||
|
if (oflags < 0)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the file */
|
||||||
|
|
||||||
fd = open(path, oflags, 0666);
|
fd = open(path, oflags, 0666);
|
||||||
|
|
||||||
/* If the open was successful, then fdopen() the fil using the file
|
/* If the open was successful, then fdopen() the fil using the file
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_fputc.c
|
* lib/stdio/lib_fputc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_fputs.c
|
* lib/stdio/lib_fputs.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_libnoflush.c
|
* lib/stdio/lib_libnoflush.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_lowoutstream.c
|
* lib/stdio/lib_lowoutstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_memoutstream.c
|
* lib/stdio/lib_memoutstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_nulloutstream.c
|
* lib/stdio/lib_nulloutstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_puts.c
|
* lib/stdio/lib_puts.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -112,7 +112,7 @@ int puts(FAR const char *s)
|
|||||||
{
|
{
|
||||||
nput = nwritten + 1;
|
nput = nwritten + 1;
|
||||||
|
|
||||||
/* Flush the buffer after the newline is output */
|
/* Flush the buffer after the newline is output. */
|
||||||
|
|
||||||
#ifdef CONFIG_STDIO_LINEBUFFER
|
#ifdef CONFIG_STDIO_LINEBUFFER
|
||||||
ret = lib_fflush(stream, true);
|
ret = lib_fflush(stream, true);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_rawoutstream.c
|
* lib/stdio/lib_rawoutstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -95,14 +97,32 @@ int stdoutstream_flush(FAR struct lib_outstream_s *this)
|
|||||||
void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream,
|
void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream,
|
||||||
FAR FILE *stream)
|
FAR FILE *stream)
|
||||||
{
|
{
|
||||||
|
/* Select the put operation */
|
||||||
|
|
||||||
stdoutstream->public.put = stdoutstream_putc;
|
stdoutstream->public.put = stdoutstream_putc;
|
||||||
|
|
||||||
|
/* Select the correct flush operation. This flush is only called when
|
||||||
|
* a newline is encountered in the output stream. However, we do not
|
||||||
|
* want to support this line buffering behavior if the stream was
|
||||||
|
* opened in binary mode. In binary mode, the newline has no special
|
||||||
|
* meaning.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_STDIO_LINEBUFFER
|
#ifdef CONFIG_STDIO_LINEBUFFER
|
||||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||||
stdoutstream->public.flush = stdoutstream_flush;
|
if ((stream->fs_oflags & O_BINARY) == 0)
|
||||||
#else
|
{
|
||||||
stdoutstream->public.flush = lib_noflush;
|
stdoutstream->public.flush = stdoutstream_flush;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
stdoutstream->public.flush = lib_noflush;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Set the number of bytes put to zero and remember the stream */
|
||||||
|
|
||||||
stdoutstream->public.nput = 0;
|
stdoutstream->public.nput = 0;
|
||||||
stdoutstream->stream = stream;
|
stdoutstream->stream = stream;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user