diff options
author | px4dev <px4@purgatory.org> | 2012-08-14 09:07:59 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-08-14 09:07:59 -0700 |
commit | 74980af6c94372e49619b905e9b1b4565930e68a (patch) | |
tree | d902ff890bb38f20c01ecd0cf0428e05d4f3ca2a | |
parent | 34118c72ef88d33d0074914c9bf0cda0232e4940 (diff) | |
parent | 3cc812dbad530e36360a992da9bc4533c016d98d (diff) | |
download | px4-firmware-74980af6c94372e49619b905e9b1b4565930e68a.tar.gz px4-firmware-74980af6c94372e49619b905e9b1b4565930e68a.tar.bz2 px4-firmware-74980af6c94372e49619b905e9b1b4565930e68a.zip |
Merge branch 'NuttX/master' from git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5027 7fd9a85b-ad96-42d3-883c-3090e2eb8679
45 files changed, 625 insertions, 248 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 1bb2a08b5..01ef090a0 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -274,3 +274,7 @@ no arguments outputs a short list of commands. With -v lists all command line details. And command name can be added to just get help on one command. + * system/readline.c: If character input/output is interrupted by a + signal, then readline() will try the read/write again. + * apps/*/Make.defs: Numerous fixes needed to use the automated + configuration (from Richard Cochran). diff --git a/apps/interpreters/Make.defs b/apps/interpreters/Make.defs index 36ee7004d..2fc4b26d4 100644 --- a/apps/interpreters/Make.defs +++ b/apps/interpreters/Make.defs @@ -34,10 +34,10 @@ # ############################################################################ -if ($(CONFIG_PCODE),y) +ifeq ($(CONFIG_PCODE),y) CONFIGURED_APPS += interpreters/pcode endif -if ($(CONFIG_FICL),y) +ifeq ($(CONFIG_FICL),y) CONFIGURED_APPS += interpreters/ficl endif diff --git a/apps/namedapp/Make.defs b/apps/namedapp/Make.defs index a07b3b3c2..399fefee8 100644 --- a/apps/namedapp/Make.defs +++ b/apps/namedapp/Make.defs @@ -34,7 +34,7 @@ # ############################################################################ -if ($(CONFIG_NAMEDAPP),y) +ifeq ($(CONFIG_NAMEDAPP),y) CONFIGURED_APPS += namedapp endif diff --git a/apps/nshlib/Make.defs b/apps/nshlib/Make.defs index c72c09bce..2bacb5b79 100644 --- a/apps/nshlib/Make.defs +++ b/apps/nshlib/Make.defs @@ -34,7 +34,7 @@ # ############################################################################ -if ($(CONFIG_NSH_LIBRARY),y) +ifeq ($(CONFIG_NSH_LIBRARY),y) CONFIGURED_APPS += nshlib endif diff --git a/apps/system/Make.defs b/apps/system/Make.defs index 1ddabd337..e72f56ef5 100644 --- a/apps/system/Make.defs +++ b/apps/system/Make.defs @@ -34,18 +34,18 @@ # ############################################################################ -if ($(CONFIG_VSN_POWEROFF),y) +ifeq ($(CONFIG_VSN_POWEROFF),y) CONFIGURED_APPS += vsn/poweroff endif -if ($(CONFIG_VSN_RAMTRON),y) +ifeq ($(CONFIG_VSN_RAMTRON),y) CONFIGURED_APPS += vsn/ramtron endif -if ($(CONFIG_VSN_SDCARD),y) +ifeq ($(CONFIG_VSN_SDCARD),y) CONFIGURED_APPS += vsn/sdcard endif -if ($(CONFIG_VSN_SYSINFO),y) +ifeq ($(CONFIG_VSN_SYSINFO),y) CONFIGURED_APPS += vsn/sysinfo endif diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index f7fa6a635..bdd39e67b 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -103,13 +103,34 @@ static inline int readline_rawgetc(int infd) char buffer; ssize_t nread; - nread = read(infd, &buffer, 1); - if (nread < 1) + /* Loop until we successfully read a character (or until an unexpected + * error occurs). + */ + + do { - /* Return EOF if the end of file (0) or error (-1) occurs */ + /* Read one character from the incoming stream */ + + nread = read(infd, &buffer, 1); + + /* Return EOF if the end of file (0) or error (-1) occurs. */ + + if (nread < 1) + { + /* EINTR is not really an error; it simply means that a signal we + * received while watiing for intput. + */ - return EOF; + if (nread == 0 || errno != EINTR) + { + return EOF; + } + } } + while (nread < 1); + + /* On success, returnt he character that was read */ + return (int)buffer; } @@ -121,7 +142,26 @@ static inline int readline_rawgetc(int infd) static inline void readline_consoleputc(int ch, int outfd) { char buffer = ch; - (void)write(outfd, &buffer, 1); + ssize_t nwritten; + + /* Loop until we successfully write a character (or until an unexpected + * error occurs). + */ + + do + { + /* Write the character to the outgoing stream */ + + nwritten = write(outfd, &buffer, 1); + + /* Check for irrecoverable write errors. */ + + if (nwritten < 0 && errno != EINTR) + { + break; + } + } + while (nwritten < 1); } #endif diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 364de21a3..48f1866c3 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3154,3 +3154,17 @@ * arch/arm/src/stm32/stm32f2xx_dma.c and stm32f4xx_dma.c: Backed out the DMA priority change just above. The reduced SD card frequency was necessary and sufficient to resolve the problem. + * drivers/serial/serial.c: open, read, write, and poll methods may now + abort return EINTR (or a short transfer size) if a signal is received + while waiting to receive or send serial data. This behavior is required + by POSIX. + * include/sys/types.h: Define NULL to be (0) if __cplusplus is defined. + (contributed by Mike Smith) + * include/ctype.h: Remove a stray semi-colon in a definitions (Thanks + Mike Smith). + * configs/.../Make.defs. Fix C++ include path set-up in Make.defs file + for all 8-bit AVR platforms (Thanks Richard Cochran). + * lib/stdio/lib_*stream.c: Revised to handle new error return values from + serial.c. + * arch/arm/src/stm32/stm32_spi.c: SPI driver can now survice re- + initialization (Mike Smith). diff --git a/nuttx/TODO b/nuttx/TODO index f9fc558ea..543d15f70 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated August 7, 2012) +NuttX TODO List (Last updated August 12, 2012) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -16,7 +16,7 @@ nuttx/ (17) Network (net/, drivers/net) (3) USB (drivers/usbdev, drivers/usbhost) (11) Libraries (lib/) - (10) File system/Generic drivers (fs/, drivers/) + (9) File system/Generic drivers (fs/, drivers/) (5) Graphics subystem (graphics/) (1) Pascal add-on (pcode/) (1) Documentation (Documentation/) @@ -750,21 +750,6 @@ o File system / Generic drivers (fs/, drivers/) Status: Open Priority: Low - Title: SERIAL DRIVER DOES NOT RETURN WHEN SIGNAL RECEIVED - Description: The serial driver (drivers/serial) should return with an - error and errno=EINTR when an interrupt is received. However, - the serial driver just continues waiting: - - static void uart_takesem(FAR sem_t *sem) - { - while (sem_wait(sem) != 0) - { - ASSERT(*get_errno_ptr() == EINTR); - } - } - Status: Open - Priority Medium - Title: POLLHUP SUPPORT Description: All drivers that support the poll method should also report POLLHUP event when the driver is closedd. diff --git a/nuttx/arch/Kconfig b/nuttx/arch/Kconfig index 253151a3b..6e0e0fb9d 100644 --- a/nuttx/arch/Kconfig +++ b/nuttx/arch/Kconfig @@ -20,7 +20,7 @@ config ARCH_ARM config ARCH_AVR bool "AVR" ---help--- - Atmel 9-bit bit AVR and 32-bit AVR32 architectures + Atmel 8-bit bit AVR and 32-bit AVR32 architectures config ARCH_HC bool "Freescale HC" diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.c b/nuttx/arch/arm/src/stm32/stm32_spi.c index a65f1e1eb..40b1a29a0 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.c +++ b/nuttx/arch/arm/src/stm32/stm32_spi.c @@ -1370,9 +1370,8 @@ FAR struct spi_dev_s *up_spiinitialize(int port) /* Only configure if the port is not already configured */ - if (!(spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE)) + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) { - /* Configure SPI1 pins: SCK, MISO, and MOSI */ stm32_configgpio(GPIO_SPI1_SCK); @@ -1395,19 +1394,18 @@ FAR struct spi_dev_s *up_spiinitialize(int port) /* Only configure if the port is not already configured */ - if (!(spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE)) + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) { + /* Configure SPI2 pins: SCK, MISO, and MOSI */ - /* Configure SPI2 pins: SCK, MISO, and MOSI */ - - stm32_configgpio(GPIO_SPI2_SCK); - stm32_configgpio(GPIO_SPI2_MISO); - stm32_configgpio(GPIO_SPI2_MOSI); + stm32_configgpio(GPIO_SPI2_SCK); + stm32_configgpio(GPIO_SPI2_MISO); + stm32_configgpio(GPIO_SPI2_MOSI); - /* Set up default configuration: Master, 8-bit, etc. */ + /* Set up default configuration: Master, 8-bit, etc. */ - spi_portinitialize(priv); - } + spi_portinitialize(priv); + } } else #endif @@ -1420,9 +1418,8 @@ FAR struct spi_dev_s *up_spiinitialize(int port) /* Only configure if the port is not already configured */ - if (!(spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE)) + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) { - /* Configure SPI3 pins: SCK, MISO, and MOSI */ stm32_configgpio(GPIO_SPI3_SCK); @@ -1432,7 +1429,7 @@ FAR struct spi_dev_s *up_spiinitialize(int port) /* Set up default configuration: Master, 8-bit, etc. */ spi_portinitialize(priv); - } + } } #endif diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index ea4ceb0c0..b289bb80b 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -113,16 +113,29 @@ static const struct file_operations g_serialops = * Name: uart_takesem ************************************************************************************/ -static void uart_takesem(FAR sem_t *sem) +static int uart_takesem(FAR sem_t *sem, bool errout) { - while (sem_wait(sem) != 0) + /* Loop, ignoring interrupts, until we have successfully acquired the semaphore */ + + while (sem_wait(sem) != OK) { - /* The only case that an error should occur here is if - * the wait was awakened by a signal. + /* The only case that an error should occur here is if the wait was awakened + * by a signal. */ ASSERT(get_errno() == EINTR); + + /* When the signal is received, should we errout? Or should we just continue + * waiting until we have the semaphore? + */ + + if (errout) + { + return -EINTR; + } } + + return OK; } /************************************************************************************ @@ -162,10 +175,11 @@ static void uart_pollnotify(FAR uart_dev_t *dev, pollevent_t eventset) * Name: uart_putxmitchar ************************************************************************************/ -static void uart_putxmitchar(FAR uart_dev_t *dev, int ch) +static int uart_putxmitchar(FAR uart_dev_t *dev, int ch) { irqstate_t flags; int nexthead; + int ret; /* Increment to see what the next head pointer will be. We need to use the "next" * head pointer to determine when the circular buffer would overrun @@ -185,36 +199,50 @@ static void uart_putxmitchar(FAR uart_dev_t *dev, int ch) { dev->xmit.buffer[dev->xmit.head] = ch; dev->xmit.head = nexthead; - return; + return OK; } else { - /* Inform the interrupt level logic that we are waiting. - * This and the following steps must be atomic. + /* Inform the interrupt level logic that we are waiting. This and + * the following steps must be atomic. */ flags = irqsave(); dev->xmitwaiting = true; - /* Wait for some characters to be sent from the buffer - * with the TX interrupt enabled. When the TX interrupt - * is enabled, uart_xmitchars should execute and remove - * some of the data from the TX buffer. + /* Wait for some characters to be sent from the buffer with the TX + * interrupt enabled. When the TX interrupt is enabled, uart_xmitchars + * should execute and remove some of the data from the TX buffer. */ uart_enabletxint(dev); - uart_takesem(&dev->xmitsem); + ret = uart_takesem(&dev->xmitsem, true); uart_disabletxint(dev); irqrestore(flags); + + /* Check if we were awakened by signal. */ + + if (ret < 0) + { + /* A signal received while waiting for the xmit buffer to become + * non-full will abort the transfer. + */ + + return -EINTR; + } } } + + /* We won't get here */ + + return OK; } /************************************************************************************ * Name: uart_irqwrite ************************************************************************************/ -static ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer, size_t buflen) +static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer, size_t buflen) { ssize_t ret = buflen; @@ -223,14 +251,17 @@ static ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer, size_t for (; buflen; buflen--) { int ch = *buffer++; - uart_putc(ch); - /* If this is the console, then we should replace LF with LF-CR */ + /* If this is the console, then we should replace LF with CR-LF */ if (ch == '\n') { uart_putc('\r'); } + + /* Output the character, using the low-level direct UART interfaces */ + + uart_putc(ch); } return ret; @@ -242,18 +273,22 @@ static ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer, size_t static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { - FAR struct inode *inode = filep->f_inode; - FAR uart_dev_t *dev = inode->i_private; - ssize_t ret = buflen; - - /* We may receive console writes through this path from - * interrupt handlers and from debug output in the IDLE task! - * In these cases, we will need to do things a little - * differently. + FAR struct inode *inode = filep->f_inode; + FAR uart_dev_t *dev = inode->i_private; + ssize_t nread = buflen; + int ret; + + /* We may receive console writes through this path from interrupt handlers and + * from debug output in the IDLE task! In these cases, we will need to do things + * a little differently. */ if (up_interrupt_context() || getpid() == 0) { + /* up_putc() will be used to generate the output in a busy-wait loop. + * up_putc() is only available for the console device. + */ + if (dev->isconsole) { irqstate_t flags = irqsave(); @@ -263,13 +298,22 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t } else { - return ERROR; + return -EPERM; } } - /* Only one user can be accessing dev->xmit.head at once */ + /* Only one user can access dev->xmit.head at a time */ - uart_takesem(&dev->xmit.sem); + ret = (ssize_t)uart_takesem(&dev->xmit.sem, true); + if (ret < 0) + { + /* A signal received while waiting for access to the xmit.head will + * abort the transfer. After the transfer has started, we are committed + * and signals will be ignored. + */ + + return ret; + } /* Loop while we still have data to copy to the transmit buffer. * we add data to the head of the buffer; uart_xmitchars takes the @@ -281,15 +325,50 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t { int ch = *buffer++; + /* If the ONLCR flag is set, we should translate \n to \r\n */ + + ret = OK; + if ((ch == '\n') && (dev->termios_s.c_oflag && ONLCR)) + { + ret = uart_putxmitchar(dev, '\r'); + } + /* Put the character into the transmit buffer */ - uart_putxmitchar(dev, ch); + if (ret == OK) + { + ret = uart_putxmitchar(dev, ch); + } - /* If this is the console, then we should replace LF with LF-CR */ + /* Were we awakened by a signal? That should be the only condition that + * uart_putxmitchar() should return an error. + */ - if ((dev->termios_s.c_oflag && ONLCR) && ch == '\n') + if (ret < 0) { - uart_putxmitchar(dev, '\r'); + /* POSIX requires that we return -1 and errno set if no data was + * transferred. Otherwise, we return the number of bytes in the + * interrupted transfer. + */ + + if (buflen < nread) + { + /* Some data was transferred. Return the number of bytes that were + * successfully transferred. + */ + + nread -= buflen; + } + else + { + /* No data was transferred. Return -EINTR. The VFS layer will + * set the errno value appropriately). + */ + + nread = -EINTR; + } + + break; } } @@ -299,7 +378,7 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t } uart_givesem(&dev->xmit.sem); - return ret; + return nread; } /************************************************************************************ @@ -313,10 +392,20 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen irqstate_t flags; ssize_t recvd = 0; int16_t tail; + int ret; + + /* Only one user can access dev->recv.tail at a time */ - /* Only one user can be accessing dev->recv.tail at once */ + ret = uart_takesem(&dev->recv.sem, true); + if (ret < 0) + { + /* A signal received while waiting for access to the recv.tail will avort + * the transfer. After the transfer has started, we are committed and + * signals will be ignored. + */ - uart_takesem(&dev->recv.sem); + return ret; + } /* Loop while we still have data to copy to the receive buffer. * we add data to the head of the buffer; uart_xmitchars takes the @@ -353,6 +442,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen { tail = 0; } + dev->recv.tail = tail; } @@ -427,12 +517,34 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen uart_enablerxint(dev); /* Now wait with the Rx interrupt re-enabled. NuttX will - * automatically re-enable global interrupts when this - * thread goes to sleep. + * automatically re-enable global interrupts when this thread + * goes to sleep. */ - uart_takesem(&dev->recvsem); + ret = uart_takesem(&dev->recvsem, true); irqrestore(flags); + + /* Was a signal received while waiting for data to be received? */ + + if (ret < 0) + { + /* POSIX requires that we return after a signal is received. + * If some bytes were read, we need to return the number of bytes + * read; if no bytes were read, we need to return -1 with the + * errno set correctly. + */ + + if (recvd == 0) + { + /* No bytes were read, return -EINTR (the VFS layer will + * set the errno value appropriately. + */ + + recvd = -EINTR; + } + + break; + } } else { @@ -513,7 +625,7 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) FAR uart_dev_t *dev = inode->i_private; pollevent_t eventset; int ndx; - int ret = OK; + int ret; int i; /* Some sanity checking */ @@ -527,7 +639,16 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) /* Are we setting up the poll? Or tearing it down? */ - uart_takesem(&dev->pollsem); + ret = uart_takesem(&dev->pollsem, true); + if (ret < 0) + { + /* A signal received while waiting for access to the poll data + * will abort the operation. + */ + + return ret; + } + if (setup) { /* This is a request to set up the poll. Find an available @@ -555,31 +676,43 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) goto errout; } - /* Should immediately notify on any of the requested events? + /* Should we immediately notify on any of the requested events? * First, check if the xmit buffer is full. + * + * Get exclusive access to the xmit buffer indices. NOTE: that we do not + * let this wait be interrupted by a signal (we probably should, but that + * would be a little awkward). */ eventset = 0; + (void)uart_takesem(&dev->xmit.sem, false); - uart_takesem(&dev->xmit.sem); ndx = dev->xmit.head + 1; if (ndx >= dev->xmit.size) { ndx = 0; } + if (ndx != dev->xmit.tail) { eventset |= POLLOUT; } + uart_givesem(&dev->xmit.sem); - /* Check if the receive buffer is empty */ + /* Check if the receive buffer is empty + * + * Get exclusive access to the recv buffer indices. NOTE: that we do not + * let this wait be interrupted by a signal (we probably should, but that + * would be a little awkward). + */ - uart_takesem(&dev->recv.sem); + (void)uart_takesem(&dev->recv.sem, false); if (dev->recv.head != dev->recv.tail) { eventset |= POLLIN; } + uart_givesem(&dev->recv.sem); if (eventset) @@ -629,7 +762,13 @@ static int uart_close(FAR struct file *filep) FAR uart_dev_t *dev = inode->i_private; irqstate_t flags; - uart_takesem(&dev->closesem); + /* Get exclusive access to the close semaphore (to synchronize open/close operations. + * NOTE: that we do not let this wait be interrupted by a signal. Technically, we + * should, but almost no one every checks the return value from close() so we avoid + * a potential memory leak by ignoring signals in this case. + */ + + (void)uart_takesem(&dev->closesem, false); if (dev->open_count > 1) { dev->open_count--; @@ -694,11 +833,19 @@ static int uart_open(FAR struct file *filep) struct inode *inode = filep->f_inode; uart_dev_t *dev = inode->i_private; uint8_t tmp; - int ret = OK; + int ret; - /* If the port is the middle of closing, wait until the close is finished */ + /* If the port is the middle of closing, wait until the close is finished. + * If a signal is received while we are waiting, then return EINTR. + */ + + ret = uart_takesem(&dev->closesem, true); + if (ret < 0) + { + /* A signal received while waiting for the last close operation. */ - uart_takesem(&dev->closesem); + return ret; + } /* Start up serial port */ /* Increment the count of references to the device. */ diff --git a/nuttx/include/ctype.h b/nuttx/include/ctype.h index 6959a44b1..22b325eef 100644 --- a/nuttx/include/ctype.h +++ b/nuttx/include/ctype.h @@ -72,7 +72,7 @@ * ****************************************************************************/ -#define isascii(c) ((c) >= 0 && (c) <= 0x7f); +#define isascii(c) ((c) >= 0 && (c) <= 0x7f) /**************************************************************************** * Name: isprint diff --git a/nuttx/include/netinet/arp.h b/nuttx/include/netinet/arp.h index 34cfc84a4..e318945aa 100644 --- a/nuttx/include/netinet/arp.h +++ b/nuttx/include/netinet/arp.h @@ -58,14 +58,17 @@ #define SIOCDARP _ARPIOC(2) /* Delete an ARP mapping */ #define SIOCGARP _ARPIOC(3) /* Get an ARP mapping */ -/* Values for the FLAGS field in struct arpreq */ - -#define ATF_COM 0x01 /* Lookup complete */ -#define ATF_PERM 0x02 /* Permanent entry */ -#define ATF_PUBL 0x04 /* Publish entry */ -#define ATF_USETRAILERS 0x10 /* Trailers requested */ -#define ATF_NETMASK 0x20 /* Use a netmask */ -#define ATF_DONTPUB 0x40 /* Don't answer */ +/* Definitions for bits in field arp_flags of struct arpreq. If the + * ATF_NETMASK flag is set, then arp_netmask should be valid. This should + * be set to 0xffffffff, or 0 to remove an existing arp entry. + */ + +#define ATF_COM (1 << 0) /* Lookup complete */ +#define ATF_PERM (1 << 1) /* Permanent entry */ +#define ATF_PUBL (1 << 2) /* Publish entry */ +#define ATF_USETRAILERS (1 << 3) /* Trailers requested (obsolete) */ +#define ATF_NETMASK (1 << 4) /* Use a netmask */ +#define ATF_DONTPUB (1 << 5) /* Don't answer */ /**************************************************************************** * Public Type Definitions diff --git a/nuttx/include/nuttx/net/ioctl.h b/nuttx/include/nuttx/net/ioctl.h index 5bce5eaf1..be3f597f4 100644 --- a/nuttx/include/nuttx/net/ioctl.h +++ b/nuttx/include/nuttx/net/ioctl.h @@ -149,6 +149,7 @@ /**************************************************************************** * Type Definitions ****************************************************************************/ +/* See include/net/if.h */ /**************************************************************************** * Public Function Prototypes diff --git a/nuttx/include/sys/types.h b/nuttx/include/sys/types.h index 6014b9b74..2ae69d4a7 100644 --- a/nuttx/include/sys/types.h +++ b/nuttx/include/sys/types.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/sys/types.h * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -63,8 +63,11 @@ /* NULL is usually defined in stddef.h (which includes this file) */ #ifndef NULL - /* SDCC is sensitive to NULL pointer type conversions */ -# ifdef SDCC + /* SDCC is sensitive to NULL pointer type conversions, and C++ defines + * NULL as zero + */ + +# if defined(SDCC) || defined(__cplusplus) # define NULL (0) # else # define NULL ((void*)0) diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile index 772c6f6a8..fc8f0c4dd 100644 --- a/nuttx/lib/Makefile +++ b/nuttx/lib/Makefile @@ -34,6 +34,13 @@ ########################################################################### -include $(TOPDIR)/Make.defs + +ASRCS = +CSRCS = + +DEPPATH := --dep-path . +VPATH := . + include stdio/Make.defs include stdlib/Make.defs include unistd/Make.defs @@ -52,41 +59,12 @@ include termios/Make.defs include queue/Make.defs include misc/Make.defs -ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) - -CSRCS = $(STDIO_SRCS) $(STDLIB_SRCS) $(UNISTD_SRCS) $(SCHED_SRCS) \ - $(STRING_SRCS) $(PTHREAD_SRCS) $(SEM_SRCS) $(SIG_SRCS) $(MQUEUE_SRCS) \ - $(MATH_SRCS) $(NET_SRCS) $(TIME_SRCS) $(LIBGEN_SRCS) \ - $(DIRENT_SRCS) $(TERMIOS_SRCS) \ - $(QUEUE_SRCS) $(MISC_SRCS) $(REGEX_SRCS) $(CRC_SRCS) $(DBG_SRCS) COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) -ROOTDEPPATH = --dep-path . -STDIODEPPATH = --dep-path stdio -STDLIBDEPPATH = --dep-path stdlib -UNISTDDEPPATH = --dep-path unistd -SCHEDDEPPATH = --dep-path sched -STRINGDEPPATH = --dep-path string -PTHREADDEPPATH = --dep-path pthread -SEMDEPPATH = --dep-path semaphore -SIGDEPPATH = --dep-path signal -MQDEPPATH = --dep-path mqueue -MATHDEPPATH = --dep-path math -NETDEPPATH = --dep-path net -TIMEDEPPATH = --dep-path time -LIBGENDEPPATH = --dep-path libgen -DIRENTDEPPATH = --dep-path dirent -TERMIOSDEPPATH = --dep-path termios -QUEUEDEPPATH = --dep-path queue -MISCDEPPATH = --dep-path misc - -VPATH = stdio:stdlib:unistd:sched:string:pthread:semaphore:signal:mqueue -VPATH += :math:net:time:libgen:dirent:termios:queue:misc - UBIN = libulib$(LIBEXT) KBIN = libklib$(LIBEXT) BIN = liblib$(LIBEXT) @@ -121,12 +99,7 @@ $(KBIN): uclean .kernlib endif .depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) $(STDIODEPPATH) $(STDLIBDEPPATH) \ - $(UNISTDDEPPATH) $(SCHEDDEPPATH) $(STRINGDEPPATH) $(PTHREADDEPPATH) \ - $(SEMDEPPATH) $(SIGDEPPATH) $(MQDEPPATH) $(MATHDEPPATH) $(NETDEPPATH) \ - $(TIMEDEPPATH) $(LIBGENDEPPATH) $(DIRENTDEPPATH) $(TERMIOSDEPPATH) \ - $(QUEUEDEPPATH) $(MISCDEPPATH) \ - $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep @touch $@ depend: .depend diff --git a/nuttx/lib/dirent/Make.defs b/nuttx/lib/dirent/Make.defs index d9dc8c29b..cc1d6b783 100644 --- a/nuttx/lib/dirent/Make.defs +++ b/nuttx/lib/dirent/Make.defs @@ -33,8 +33,16 @@ # ############################################################################ -DIRENT_SRCS = ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -DIRENT_SRCS += lib_readdirr.c lib_telldir.c + +# Add the dirent C files to the build + +CSRCS += lib_readdirr.c lib_telldir.c + +# Add the dirent directory to the build + +DEPPATH += --dep-path dirent +VPATH += :dirent + endif diff --git a/nuttx/lib/libgen/Make.defs b/nuttx/lib/libgen/Make.defs index 93214eadb..f12645512 100644 --- a/nuttx/lib/libgen/Make.defs +++ b/nuttx/lib/libgen/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/libgen/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,5 +33,11 @@ # ############################################################################ -LIBGEN_SRCS = lib_basename.c lib_dirname.c +# Add the libgen C files to the build +CSRCS += lib_basename.c lib_dirname.c + +# Add the libgen directory to the build + +DEPPATH += --dep-path libgen +VPATH += :libgen diff --git a/nuttx/lib/math/Make.defs b/nuttx/lib/math/Make.defs index c3b071298..126cd2f47 100644 --- a/nuttx/lib/math/Make.defs +++ b/nuttx/lib/math/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/math/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,5 +33,11 @@ # ############################################################################ -MATH_SRCS = lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c +# Add the math C files to the build +CSRCS += lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c + +# Add the math directory to the build + +DEPPATH += --dep-path math +VPATH += :math diff --git a/nuttx/lib/misc/Make.defs b/nuttx/lib/misc/Make.defs index 8892f71e6..484f822d0 100644 --- a/nuttx/lib/misc/Make.defs +++ b/nuttx/lib/misc/Make.defs @@ -33,18 +33,23 @@ # ############################################################################ -MISC_SRCS = lib_init.c lib_filesem.c +# Add the internal C files to the build + +CSRCS += lib_init.c lib_filesem.c ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) ifneq ($(CONFIG_NFILE_STREAMS),0) -MISC_SRCS += lib_streamsem.c +CSRCS += lib_streamsem.c endif endif -REGEX_SRCS = lib_match.c - -CRC_SRCS = lib_crc32.c +# Add the miscellaneous C files to the build -DBG_SRCS = lib_dbg.c lib_dumpbuffer.c +CSRCS += lib_match.c +CSRCS += lib_crc32.c +CSRCS += lib_dbg.c lib_dumpbuffer.c +# Add the misc directory to the build +DEPPATH += --dep-path misc +VPATH += :misc diff --git a/nuttx/lib/mqueue/Make.defs b/nuttx/lib/mqueue/Make.defs index cd2091e99..40dc6c13e 100644 --- a/nuttx/lib/mqueue/Make.defs +++ b/nuttx/lib/mqueue/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/mqueue/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -34,6 +34,15 @@ ############################################################################ ifneq ($(CONFIG_DISABLE_MQUEUE),y) -MQUEUE_SRCS = mq_setattr.c mq_getattr.c + +# Add the mqueue C files to the build + +CSRCS += mq_setattr.c mq_getattr.c + +# Add the mqueue directory to the build + +DEPPATH += --dep-path mqueue +VPATH += :mqueue + endif diff --git a/nuttx/lib/net/Make.defs b/nuttx/lib/net/Make.defs index 94ac6db03..ae041bd2c 100644 --- a/nuttx/lib/net/Make.defs +++ b/nuttx/lib/net/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/net/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,5 +33,12 @@ # ############################################################################ -NET_SRCS = lib_etherntoa.c lib_htons.c lib_htonl.c lib_inetaddr.c -NET_SRCS += lib_inetntoa.c lib_inetntop.c lib_inetpton.c +# Add the networking C files to the build + +CSRCS += lib_etherntoa.c lib_htons.c lib_htonl.c lib_inetaddr.c +CSRCS += lib_inetntoa.c lib_inetntop.c lib_inetpton.c + +# Add the net directory to the build + +DEPPATH += --dep-path net +VPATH += :net diff --git a/nuttx/lib/pthread/Make.defs b/nuttx/lib/pthread/Make.defs index 47211f9b9..a1eba7bb0 100644 --- a/nuttx/lib/pthread/Make.defs +++ b/nuttx/lib/pthread/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/pthread/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,7 +33,9 @@ # ############################################################################ -PTHREAD_SRCS = pthread_attrinit.c pthread_attrdestroy.c \ +# Add the pthread C files to the build + +CSRCS += pthread_attrinit.c pthread_attrdestroy.c \ pthread_attrsetschedpolicy.c pthread_attrgetschedpolicy.c \ pthread_attrsetinheritsched.c pthread_attrgetinheritsched.c \ pthread_attrsetstacksize.c pthread_attrgetstacksize.c \ @@ -45,5 +47,10 @@ PTHREAD_SRCS = pthread_attrinit.c pthread_attrdestroy.c \ pthread_mutexattrgetpshared.c pthread_mutexattrsetpshared.c ifeq ($(CONFIG_MUTEX_TYPES),y) -PTHREAD_SRCS += pthread_mutexattrsettype.c pthread_mutexattrgettype.c +CSRCS += pthread_mutexattrsettype.c pthread_mutexattrgettype.c endif + +# Add the pthread directory to the build + +DEPPATH += --dep-path pthread +VPATH += :pthread diff --git a/nuttx/lib/queue/Make.defs b/nuttx/lib/queue/Make.defs index 94e8125e7..976e7a2b8 100644 --- a/nuttx/lib/queue/Make.defs +++ b/nuttx/lib/queue/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/queue/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,8 +33,15 @@ # ############################################################################ -QUEUE_SRCS = sq_addlast.c sq_addfirst.c sq_addafter.c \ +# Add the queue C files to the build + +CSRCS += sq_addlast.c sq_addfirst.c sq_addafter.c \ sq_rem.c sq_remlast.c sq_remfirst.c sq_remafter.c -QUEUE_SRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c \ +CSRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c \ dq_rem.c dq_remlast.c dq_remfirst.c + +# Add the queue directory to the build + +DEPPATH += --dep-path queue +VPATH += :queue diff --git a/nuttx/lib/sched/Make.defs b/nuttx/lib/sched/Make.defs index 939cb983f..f398b755e 100644 --- a/nuttx/lib/sched/Make.defs +++ b/nuttx/lib/sched/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/sched/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,6 +33,11 @@ # ############################################################################ -SCHED_SRCS = sched_getprioritymax.c sched_getprioritymin.c +# Add the sched C files to the build +CSRCS += sched_getprioritymax.c sched_getprioritymin.c +# Add the sched directory to the build + +DEPPATH += --dep-path sched +VPATH += :sched diff --git a/nuttx/lib/semaphore/Make.defs b/nuttx/lib/semaphore/Make.defs index 996d320fe..fdc0fe7d5 100644 --- a/nuttx/lib/semaphore/Make.defs +++ b/nuttx/lib/semaphore/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/semaphore/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,4 +33,11 @@ # ############################################################################ -SEM_SRCS = sem_init.c sem_getvalue.c +# Add the semaphore C files to the build + +CSRCS += sem_init.c sem_getvalue.c + +# Add the semaphore directory to the build + +DEPPATH += --dep-path semaphore +VPATH += :semaphore diff --git a/nuttx/lib/signal/Make.defs b/nuttx/lib/signal/Make.defs index 0c66efa73..e27da9b2e 100644 --- a/nuttx/lib/signal/Make.defs +++ b/nuttx/lib/signal/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/signal/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -34,7 +34,14 @@ ############################################################################ ifneq ($(CONFIG_DISABLE_SIGNALS),y) -SIG_SRCS = sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c sig_ismember.c -endif +# Add the signal C files to the build + +CSRCS += sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c sig_ismember.c + +# Add the signal directory to the build +DEPPATH += --dep-path signal +VPATH += :signal + +endif diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs index ddccaca71..1165d5354 100644 --- a/nuttx/lib/stdio/Make.defs +++ b/nuttx/lib/stdio/Make.defs @@ -33,7 +33,9 @@ # ############################################################################ -STDIO_SRCS = lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ +# Add the stdio C files to the build + +CSRCS += lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \ lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \ lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \ @@ -41,9 +43,9 @@ STDIO_SRCS = lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ lib_nulloutstream.c lib_sscanf.c ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -STDIO_SRCS += lib_rawinstream.c lib_rawoutstream.c +CSRCS += lib_rawinstream.c lib_rawoutstream.c ifneq ($(CONFIG_NFILE_STREAMS),0) -STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ +CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \ lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \ lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \ @@ -53,13 +55,18 @@ endif endif ifeq ($(CONFIG_SYSLOG),y) -STDIO_SRCS += lib_syslogstream.c +CSRCS += lib_syslogstream.c endif ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) -STDIO_SRCS += lib_dtoa.c +CSRCS += lib_dtoa.c endif ifeq ($(CONFIG_STDIO_LINEBUFFER),y) -STDIO_SRCS += lib_libnoflush.c +CSRCS += lib_libnoflush.c endif + +# Add the stdio directory to the build + +DEPPATH += --dep-path stdio +VPATH += :stdio diff --git a/nuttx/lib/stdio/lib_libfwrite.c b/nuttx/lib/stdio/lib_libfwrite.c index e2c35e3e9..e71866b49 100644 --- a/nuttx/lib/stdio/lib_libfwrite.c +++ b/nuttx/lib/stdio/lib_libfwrite.c @@ -2,7 +2,7 @@ * lib/stdio/lib_libfwrite.c * * Copyright (C) 2007-2009, 2011 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 * modification, are permitted provided that the following conditions diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/lib/stdio/lib_lowinstream.c index 6dcc4a37e..c97a4721f 100644 --- a/nuttx/lib/stdio/lib_lowinstream.c +++ b/nuttx/lib/stdio/lib_lowinstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_lowinstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +42,9 @@ #ifdef CONFIG_ARCH_LOWGETC #include <stdio.h> +#include <assert.h> #include <errno.h> + #include <nuttx/arch.h> #include "lib_internal.h" @@ -57,10 +59,19 @@ static int lowinstream_getc(FAR struct lib_instream_s *this) { - if (this && up_getc(ch) != EOF) + int ret; + + DEBUGASSERT(this); + + /* Get the next character from the incoming stream */ + + ret = up_getc(ch) + if (ret != EOF) { this->nget++; } + + return ret; } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_lowoutstream.c b/nuttx/lib/stdio/lib_lowoutstream.c index 726bd84d7..092f39ca2 100644 --- a/nuttx/lib/stdio/lib_lowoutstream.c +++ b/nuttx/lib/stdio/lib_lowoutstream.c @@ -42,6 +42,7 @@ #ifdef CONFIG_ARCH_LOWPUTC #include <stdio.h> +#include <assert.h> #include <errno.h> #include <nuttx/arch.h> @@ -57,7 +58,9 @@ static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch) { - if (this && up_putc(ch) != EOF) + DEBUGASSERT(this); + + if (up_putc(ch) != EOF) { this->nput++; } diff --git a/nuttx/lib/stdio/lib_meminstream.c b/nuttx/lib/stdio/lib_meminstream.c index 839e56219..a842096fb 100644 --- a/nuttx/lib/stdio/lib_meminstream.c +++ b/nuttx/lib/stdio/lib_meminstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_meminstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,6 +37,8 @@ * Included Files ****************************************************************************/ +#include <assert.h> + #include "lib_internal.h" /**************************************************************************** @@ -52,7 +54,11 @@ static int meminstream_getc(FAR struct lib_instream_s *this) FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this; int ret; - if (this && this->nget < mthis->buflen) + DEBUGASSERT(this); + + /* Get the next character (if any) from the buffer */ + + if (this->nget < mthis->buflen) { ret = mthis->buffer[this->nget]; this->nget++; @@ -61,6 +67,7 @@ static int meminstream_getc(FAR struct lib_instream_s *this) { ret = EOF; } + return ret; } diff --git a/nuttx/lib/stdio/lib_memoutstream.c b/nuttx/lib/stdio/lib_memoutstream.c index 007ab8976..21197358b 100644 --- a/nuttx/lib/stdio/lib_memoutstream.c +++ b/nuttx/lib/stdio/lib_memoutstream.c @@ -37,6 +37,8 @@ * Included Files ****************************************************************************/ +#include <assert.h> + #include "lib_internal.h" /**************************************************************************** @@ -51,12 +53,14 @@ static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch) { FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this; + DEBUGASSERT(this); + /* If this will not overrun the buffer, then write the character to the * buffer. Not that buflen was pre-decremented when the stream was * created so it is okay to write past the end of the buflen by one. */ - if (this && this->nput < mthis->buflen) + if (this->nput < mthis->buflen) { mthis->buffer[this->nput] = ch; this->nput++; diff --git a/nuttx/lib/stdio/lib_nullinstream.c b/nuttx/lib/stdio/lib_nullinstream.c index 271cba396..0eadb0a8e 100644 --- a/nuttx/lib/stdio/lib_nullinstream.c +++ b/nuttx/lib/stdio/lib_nullinstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_nullinstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,6 +39,7 @@ #include <stdio.h> #include <errno.h> + #include "lib_internal.h" /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_nulloutstream.c b/nuttx/lib/stdio/lib_nulloutstream.c index 520df459e..69878fd57 100644 --- a/nuttx/lib/stdio/lib_nulloutstream.c +++ b/nuttx/lib/stdio/lib_nulloutstream.c @@ -38,7 +38,9 @@ ****************************************************************************/ #include <stdio.h> +#include <assert.h> #include <errno.h> + #include "lib_internal.h" /**************************************************************************** @@ -47,6 +49,7 @@ static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch) { + DEBUGASSERT(this); this->nput++; } diff --git a/nuttx/lib/stdio/lib_rawinstream.c b/nuttx/lib/stdio/lib_rawinstream.c index ead3116b4..9671a2716 100644 --- a/nuttx/lib/stdio/lib_rawinstream.c +++ b/nuttx/lib/stdio/lib_rawinstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_rawinstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,9 @@ ****************************************************************************/ #include <unistd.h> +#include <assert.h> #include <errno.h> + #include "lib_internal.h" /**************************************************************************** @@ -52,23 +54,26 @@ static int rawinstream_getc(FAR struct lib_instream_s *this) { FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this; + int nwritten; char ch; - if (this && rthis->fd >= 0) + DEBUGASSERT(this && rthis->fd >= 0); + + /* Attempt to read one character */ + + nwritten = read(rthis->fd, &ch, 1); + if (nwritten == 1) { - int nwritten; - do - { - nwritten = read(rthis->fd, &ch, 1); - if (nwritten == 1) - { - this->nget++; - return ch; - } - } - while (nwritten < 0 && get_errno() == EINTR); + this->nget++; + return ch; } + /* Return EOF on any failure to read from the incoming byte stream. The + * only expected error is EINTR meaning that the read was interrupted + * by a signal. A Zero return value would indicated an end-of-file + * confition. + */ + return EOF; } diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c index ce9d33280..ed813f87a 100644 --- a/nuttx/lib/stdio/lib_rawoutstream.c +++ b/nuttx/lib/stdio/lib_rawoutstream.c @@ -38,7 +38,9 @@ ****************************************************************************/ #include <unistd.h> +#include <assert.h> #include <errno.h> + #include "lib_internal.h" /**************************************************************************** @@ -52,20 +54,32 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) { FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; + int nwritten; char buffer = ch; - if (this && rthis->fd >= 0) + + DEBUGASSERT(this && rthis->fd >= 0); + + /* Loop until the character is successfully transferred or until an + * irrecoverable error occurs. + */ + + do { - int nwritten; - do + nwritten = write(rthis->fd, &buffer, 1); + if (nwritten == 1) { - nwritten = write(rthis->fd, &buffer, 1); - if (nwritten == 1) - { - this->nput++; - } + this->nput++; + return; } - while (nwritten < 0 && get_errno() == EINTR); + + /* The only expected error is EINTR, meaning that the write operation + * was awakened by a signal. Zero would not be a valid return value + * from write(). + */ + + DEBUGASSERT(nwritten < 0); } + while (get_errno() == EINTR); } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_stdinstream.c b/nuttx/lib/stdio/lib_stdinstream.c index d89b6b63a..77aab9ec8 100644 --- a/nuttx/lib/stdio/lib_stdinstream.c +++ b/nuttx/lib/stdio/lib_stdinstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_stdinstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,6 +37,8 @@ * Included Files ****************************************************************************/ +#include <assert.h> + #include "lib_internal.h" /**************************************************************************** @@ -50,16 +52,19 @@ static int stdinstream_getc(FAR struct lib_instream_s *this) { FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this; - if (this) + int ret; + + DEBUGASSERT(this); + + /* Get the next character from the incoming stream */ + + ret = getc(sthis->stream); + if (ret != EOF) { - int ret = getc(sthis->stream); - if (ret != EOF) - { - this->nget++; - } - return ret; + this->nget++; } - return EOF; + + return ret; } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/lib/stdio/lib_stdoutstream.c index 12e78ce53..20da5b702 100644 --- a/nuttx/lib/stdio/lib_stdoutstream.c +++ b/nuttx/lib/stdio/lib_stdoutstream.c @@ -1,8 +1,8 @@ /**************************************************************************** * lib/stdio/lib_stdoutstream.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,6 +38,8 @@ ****************************************************************************/ #include <fcntl.h> +#include <assert.h> +#include <errno.h> #include "lib_internal.h" @@ -52,13 +54,28 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) { FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - if (this) + int result; + + DEBUGASSERT(this && sthis->stream); + + /* Loop until the character is successfully transferred or an irrecoverable + * error occurs. + */ + + do { - if (putc(ch, sthis->stream) != EOF) + result = fputc(ch, sthis->stream); + if (result != EOF) { this->nput++; + return; } + + /* EINTR (meaning that fputc was interrupted by a signal) is the only + * recoverable error. + */ } + while (get_errno() == EINTR); } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c index 20c6165ca..7e47d794a 100644 --- a/nuttx/lib/stdio/lib_syslogstream.c +++ b/nuttx/lib/stdio/lib_syslogstream.c @@ -40,6 +40,7 @@ #include <nuttx/config.h> #include <unistd.h> +#include <assert.h> #include <errno.h> #include <nuttx/syslog.h> @@ -62,10 +63,30 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) { - /* Write the character to the supported logging device */ - - (void)syslog_putc(ch); - this->nput++; + int ret; + + /* Try writing until the write was successful or until an irrecoverable + * error occurs. + */ + + do + { + /* Write the character to the supported logging device */ + + ret = syslog_putc(ch); + if (ret == OK) + { + this->nput++; + return; + } + + /* On failure syslog_putc will return a negated errno value. The + * errno variable will not be set. The special value -EINTR means that + * syslog_putc() was awakened by a signal. This is not a real error and + * must be ignored in this context. + */ + } + while (ret == -EINTR); } /**************************************************************************** diff --git a/nuttx/lib/stdlib/Make.defs b/nuttx/lib/stdlib/Make.defs index 3119ecda4..76e285808 100644 --- a/nuttx/lib/stdlib/Make.defs +++ b/nuttx/lib/stdlib/Make.defs @@ -33,6 +33,12 @@ # ############################################################################ -STDLIB_SRCS = lib_abs.c lib_abort.c lib_imaxabs.c lib_labs.c lib_llabs.c \ +# Add the stdlib C files to the build + +CSRCS += lib_abs.c lib_abort.c lib_imaxabs.c lib_labs.c lib_llabs.c \ lib_rand.c lib_qsort.c +# Add the stdlib directory to the build + +DEPPATH += --dep-path stdlib +VPATH += :stdlib diff --git a/nuttx/lib/string/Make.defs b/nuttx/lib/string/Make.defs index 86fdaba02..495634a9e 100644 --- a/nuttx/lib/string/Make.defs +++ b/nuttx/lib/string/Make.defs @@ -33,7 +33,9 @@ # ############################################################################ -STRING_SRCS = lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ +# Add the string C files to the build + +CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ lib_memccpy.c lib_memcpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \ lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \ lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \ @@ -41,3 +43,8 @@ STRING_SRCS = lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ lib_strndup.c lib_strcasestr.c lib_strpbrk.c lib_strrchr.c\ lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \ lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c + +# Add the string directory to the build + +DEPPATH += --dep-path string +VPATH += :string diff --git a/nuttx/lib/termios/Make.defs b/nuttx/lib/termios/Make.defs index c0a090bd5..a6bb77f83 100644 --- a/nuttx/lib/termios/Make.defs +++ b/nuttx/lib/termios/Make.defs @@ -33,11 +33,22 @@ # ############################################################################ -TERMIOS_SRCS = +# termios.h support requires file descriptors and that CONFIG_SERIAL_TERMIOS +# is defined ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) +ifeq ($(CONFIG_SERIAL_TERMIOS),y) -TERMIOS_SRCS += lib_cfgetspeed.c lib_cfsetspeed.c lib_tcflush.c -TERMIOS_SRCS += lib_tcgetattr.c lib_tcsetattr.c +# Add the termios C files to the build + +CSRCS += lib_cfgetspeed.c lib_cfsetspeed.c lib_tcflush.c +CSRCS += lib_tcgetattr.c lib_tcsetattr.c + +# Add the termios directory to the build + +DEPPATH += --dep-path termios +VPATH += termios endif +endif + diff --git a/nuttx/lib/time/Make.defs b/nuttx/lib/time/Make.defs index d65ba50f6..ab7414229 100644 --- a/nuttx/lib/time/Make.defs +++ b/nuttx/lib/time/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/time/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,5 +33,12 @@ # ############################################################################ -TIME_SRCS = lib_mktime.c lib_gmtime.c lib_gmtimer.c lib_strftime.c \ +# Add the time C files to the build + +CSRCS += lib_mktime.c lib_gmtime.c lib_gmtimer.c lib_strftime.c \ lib_calendar2utc.c lib_daysbeforemonth.c lib_isleapyear.c lib_time.c + +# Add the time directory to the build + +DEPPATH += --dep-path time +VPATH += :time diff --git a/nuttx/lib/unistd/Make.defs b/nuttx/lib/unistd/Make.defs index 90f172406..e1441a48d 100644 --- a/nuttx/lib/unistd/Make.defs +++ b/nuttx/lib/unistd/Make.defs @@ -1,8 +1,8 @@ ############################################################################ # lib/unistd/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <spudmonkey@racsa.co.cr> +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,10 +33,17 @@ # ############################################################################ -UNISTD_SRCS = lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c +# Add the unistd C files to the build + +CSRCS += lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c + ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) ifneq ($(CONFIG_DISABLE_ENVIRON),y) -UNISTD_SRCS += lib_chdir.c lib_getcwd.c +CSRCS += lib_chdir.c lib_getcwd.c endif endif +# Add the unistd directory to the build + +DEPPATH += --dep-path unistd +VPATH += :unistd |