diff --git a/arch/README.txt b/arch/README.txt
index 0c7e1953618ea63e2a110c92c57de75be99b0d93..bdc353cbbb9bcfa0adf896cda46d6d3b516bac81 100644
--- a/arch/README.txt
+++ b/arch/README.txt
@@ -92,11 +92,6 @@ defconfig -- This is a configuration file similar to the Linux
 		CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_BZERO
 		CONFIG_ARCH_KMALLOC, CONFIG_ARCH_KZMALLOC, CONFIG_ARCH_KFREE
 
-	General Compile environment setup
-
-		CONFIG_HAVE_LONG_LONG - enable if your architecture supports
-		  long long types and if you plan to use them
-
 	Sizes of configurable things (0 disables)
 
 		CONFIG_NPTHREAD_KEYS - The number of items of thread-
diff --git a/arch/c5471/defconfig b/arch/c5471/defconfig
index 2dd38f0144430dd934990fc83a075039bce216e3..449d1a2d2de2cd83dca2d2420722e9c2414030f2 100644
--- a/arch/c5471/defconfig
+++ b/arch/c5471/defconfig
@@ -129,32 +129,6 @@ CONFIG_ARCH_KMALLOC=n
 CONFIG_ARCH_KZMALLOC=n
 CONFIG_ARCH_KFREE=n
 
-#
-# General Compile environment setup
-#
-# CONFIG_SMALL_MEMORY - enable if your processor supports
-#   16-bit addressing; disable if it supports 32-bit.
-# CONFIG_HAVE_INLINE - enable if your compiler supports
-#   inline functions
-# CONFIG_HAVE_DOUBLE - enable if your compiler supports type
-#   double.
-# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
-#   long long types and if you plan to use them
-# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
-#   passing and assiging structures and unions as values
-# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
-#   integers and pointer.
-# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
-#   weak functions (see include/nuttx/comp
-#
-CONFIG_SMALL_MEMORY=n
-CONFIG_HAVE_INLINE=y
-CONFIG_HAVE_DOUBLE=y
-CONFIG_HAVE_LONG_LONG=n
-CONFIG_CAN_PASS_STRUCTS=y
-CONFIG_CAN_CAST_POINTERS=y
-CONFIG_HAVE_WEAKFUNCTIONS=y
-
 #
 # General build options
 #
diff --git a/arch/sim/defconfig b/arch/sim/defconfig
index 5b6f2ae6f08582de8f0d0d732d2c3307aaf233b9..00a8e6e59d97e2d1dd2db22adaf88270c79d1837 100644
--- a/arch/sim/defconfig
+++ b/arch/sim/defconfig
@@ -96,32 +96,6 @@ CONFIG_ARCH_KMALLOC=n
 CONFIG_ARCH_KZMALLOC=n
 CONFIG_ARCH_KFREE=n
 
-#
-# General Compile environment setup
-#
-# CONFIG_SMALL_MEMORY - enable if your processor supports
-#   16-bit addressing; disable if it supports 32-bit.
-# CONFIG_HAVE_INLINE - enable if your compiler supports
-#   inline functions
-# CONFIG_HAVE_DOUBLE - enable if your compiler supports type
-#   double.
-# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
-#   long long types and if you plan to use them
-# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
-#   passing  and assiging structures and unions as values
-# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
-#   integers and pointer.
-# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
-#   weak functions (see include/nuttx/comp
-#
-CONFIG_SMALL_MEMORY=n
-CONFIG_HAVE_INLINE=y
-CONFIG_HAVE_DOUBLE=y
-CONFIG_HAVE_LONG_LONG=n
-CONFIG_CAN_PASS_STRUCTS=y
-CONFIG_CAN_CAST_POINTERS=y
-CONFIG_HAVE_WEAKFUNCTIONS=y
-
 #
 # General build options
 #
diff --git a/drivers/Makefile b/drivers/Makefile
index 695dd806a423894e8c1d43c7de8efa6368b9d217..711b0ca33cb0999319250530c531391a50e1ab45 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -69,7 +69,7 @@ $(BIN):	$(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/drivers/dev_null.c b/drivers/dev_null.c
index f4211b5138451ef28eb64a7dc7c2dc751a659808..1d449df1f743cdee067366b0b4474d1f55fc8802 100644
--- a/drivers/dev_null.c
+++ b/drivers/dev_null.c
@@ -61,8 +61,11 @@ static ssize_t devnull_write(struct file *, const char *, size_t);
 
 static struct file_operations devnull_fops =
 {
-  .read		= devnull_read,
-  .write	= devnull_write,
+  NULL,          /* open */
+  NULL,          /* close */
+  devnull_read,  /* read */
+  devnull_write, /* write */
+  NULL           /* ioctl */
 };
 
 /************************************************************
diff --git a/examples/ostest/Makefile b/examples/ostest/Makefile
index df30ca841c69a1ce03319dd52a4dd888e5675363..44c7f3f067421572cca30fe5719d42dca5fe3a3a 100644
--- a/examples/ostest/Makefile
+++ b/examples/ostest/Makefile
@@ -70,7 +70,7 @@ $(BIN):	$(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/examples/ostest/cancel.c b/examples/ostest/cancel.c
index 1fda4166c90f9379c9d341eeb3574084f764fea1..c6803c0483d0bd5c3b2438a59ecbce88c03a0e0e 100644
--- a/examples/ostest/cancel.c
+++ b/examples/ostest/cancel.c
@@ -96,7 +96,7 @@ static void *thread_waiter(void *parameter)
     }
 
   printf("thread_waiter: Exit with status 0x12345678\n");
-  pthread_exit((void*)0x12345678);
+  pthread_exit((pthread_addr_t)0x12345678);
   return NULL;
 }
 
@@ -140,7 +140,7 @@ static void start_thread(pthread_t *waiter, int cancelable)
   /* Start the waiter thread  */
 
   printf("start_thread: Starting thread\n");
-  status = pthread_create(waiter, NULL, thread_waiter, (void*)cancelable);
+  status = pthread_create(waiter, &attr, thread_waiter, (pthread_addr_t)cancelable);
   if (status != 0)
     {
       printf("start_thread: ERROR pthread_create failed, status=%d\n", status);
diff --git a/examples/ostest/cond.c b/examples/ostest/cond.c
index 13e7b46697493db00adb8c14ff5e46c6ca92fead..6214ea9d07f90224a8a4a55ca6a8b71568db871f 100644
--- a/examples/ostest/cond.c
+++ b/examples/ostest/cond.c
@@ -190,6 +190,9 @@ void cond_test(void)
   pthread_t waiter;
   pthread_t signaler;
   pthread_attr_t attr;
+#ifdef SDCC
+  pthread_addr_t result;
+#endif
   struct sched_param sparam;
   int prio_min;
   int prio_max;
@@ -270,7 +273,11 @@ void cond_test(void)
 
   /* Wait for the threads to stop */
 
+#ifdef SDCC
+  pthread_join(signaler, &result);
+#else
   pthread_join(signaler, NULL);
+#endif
   printf("cond_test: signaler terminated, now cancel the waiter\n");
   pthread_detach(waiter);
   pthread_cancel(waiter);
diff --git a/examples/ostest/main.c b/examples/ostest/main.c
index 3122ef3430f3d83637d4092b2332460cda73b498..ff1072176f34a8a67534f0988e494872b4c8a5a8 100644
--- a/examples/ostest/main.c
+++ b/examples/ostest/main.c
@@ -55,18 +55,18 @@
 #define STACKSIZE 8192
 #define NARGS        4
 
-#define ARG1      "Arg1"
-#define ARG2      "Arg2"
-#define ARG3      "Arg3"
-#define ARG4      "Arg4"
-
 /************************************************************
  * Private Data
  ************************************************************/
 
+static FAR char arg1[]    = "Arg1";
+static FAR char arg2[]    = "Arg2";
+static FAR char arg3[]    = "Arg3";
+static FAR char arg4[]    = "Arg4";
+
 static char write_data1[] = "Standard I/O Check: write fd=1\n";
 static char write_data2[] = "Standard I/O Check: write fd=2\n";
-static char *args[NARGS] = { ARG1, ARG2, ARG3, ARG4 };
+static char *args[NARGS]  = { arg1, arg2, arg3, arg4 };
 
 /************************************************************
  * Private Functions
@@ -165,7 +165,7 @@ int user_start(int parm1, int parm2, int parm3, int parm4)
   /* Verify that we can spawn a new task */
 
   result = task_create("ostest", PRIORITY, STACKSIZE, user_main,
-                       ARG1, ARG2, ARG3, ARG4);
+                       arg1, arg2, arg3, arg4);
   if (result == ERROR)
     {
       fprintf(stderr, "user_start: Failed to start user_main\n");
diff --git a/examples/ostest/mqueue.c b/examples/ostest/mqueue.c
index acdbea99ebe44680c9be28723b40d12336fed66a..9e9360726ee45a14a203570e493b51cd3b8d0183 100644
--- a/examples/ostest/mqueue.c
+++ b/examples/ostest/mqueue.c
@@ -50,7 +50,11 @@
  **************************************************************************/
 
 #define TEST_MESSAGE "This is a test and only a test"
+#ifdef SDCC
+#define TEST_MSGLEN  (31)
+#else
 #define TEST_MSGLEN  (strlen(TEST_MESSAGE)+1)
+#endif
 
 /**************************************************************************
  * Private Types
@@ -108,7 +112,7 @@ static void *sender_thread(void *arg)
   if (mqfd < 0)
     {
 	printf("sender_thread: ERROR mq_open failed\n");
-        pthread_exit((void*)1);
+        pthread_exit((pthread_addr_t)1);
     }
 
   /* Fill in a test message buffer to send */
@@ -139,7 +143,7 @@ static void *sender_thread(void *arg)
     }
 
   printf("sender_thread: returning nerrors=%d\n", nerrors);
-  return (void*)nerrors;
+  return (pthread_addr_t)nerrors;
 }
 
 static void *receiver_thread(void *arg)
@@ -174,7 +178,7 @@ static void *receiver_thread(void *arg)
    if (mqfd < 0)
      {
        printf("receiver_thread: ERROR mq_open failed\n");
-       pthread_exit((void*)1);
+       pthread_exit((pthread_addr_t)1);
      }
 
    /* Perform the receive 10 times */
@@ -221,7 +225,7 @@ static void *receiver_thread(void *arg)
       nerrors++;
     }
 
-  pthread_exit((void*)nerrors);
+  pthread_exit((pthread_addr_t)nerrors);
 
   /* Destroy the queue */
 
@@ -232,7 +236,7 @@ static void *receiver_thread(void *arg)
     }
 
   printf("receiver_thread: returning nerrors=%d\n", nerrors);
-  return (void*)nerrors;
+  return (pthread_addr_t)nerrors;
 }
 
 void mqueue_test(void)
diff --git a/examples/ostest/mutex.c b/examples/ostest/mutex.c
index cb8996053c8fa97bba6b361b92d281b8344552a8..5edf60dbaac8d2d049f19357f646538dbbe6e434 100644
--- a/examples/ostest/mutex.c
+++ b/examples/ostest/mutex.c
@@ -91,6 +91,11 @@ static void *thread_func(void *parameter)
 void mutex_test(void)
 {
   pthread_t thread1, thread2;
+#ifdef SDCC
+  pthread_addr_t result1, result2;
+  pthread_attr_t attr;
+#endif
+  int status;
 
   /* Initialize the mutex */
 
@@ -100,19 +105,35 @@ void mutex_test(void)
   /* Start two thread instances */
 
   printf("Starting thread 1\n");
-  if ((pthread_create(&thread1, NULL, thread_func, (void*)1)) != 0)
+#ifdef SDCC
+  (void)pthread_attr_init(&attr);
+  status = pthread_create(&thread1, &attr, thread_func, (pthread_addr_t)1);
+#else
+  status = pthread_create(&thread1, NULL, thread_func, (pthread_addr_t)1);
+#endif
+  if (status != 0)
     {
       printf("Error in thread#1 creation\n");
     }
 
   printf("Starting thread 2\n");
-  if ((pthread_create(&thread2, NULL, thread_func, (void*)2)) != 0)
+#ifdef SDCC
+  status = pthread_create(&thread2, &attr, thread_func, (pthread_addr_t)2);
+#else
+  status = pthread_create(&thread2, NULL, thread_func, (pthread_addr_t)2);
+#endif
+  if (status != 0)
     {
       printf("Error in thread#2 creation\n");
     }
 
+#ifdef SDCC
+  pthread_join(thread1, &result1);
+  pthread_join(thread2, &result2);
+#else
   pthread_join(thread1, NULL);
   pthread_join(thread2, NULL);
+#endif
 
   printf("\t\tThread1\tThread2\n");
   printf("\tLoops\t%ld\t%ld\n", nloops[0], nloops[1]);
diff --git a/examples/ostest/sem.c b/examples/ostest/sem.c
index 73be6910e36debda17805ea6e6b40fcefc4ba6c2..f6e6ddbb51dd9c6d30dac50f20b18b95664d0381 100644
--- a/examples/ostest/sem.c
+++ b/examples/ostest/sem.c
@@ -144,6 +144,9 @@ void sem_test(void)
   pthread_t waiter_thread1;
   pthread_t waiter_thread2;
   pthread_t poster_thread;
+#ifdef SDCC
+  pthread_addr_t result;
+#endif
   struct sched_param sparam;
   int prio_min;
   int prio_max;
@@ -178,7 +181,7 @@ void sem_test(void)
       printf("sem_test: Set thread 1 priority to %d\n",  sparam.sched_priority);
     }
 
-  status = pthread_create(&waiter_thread1, &attr, waiter_func, (void*)1);
+  status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1);
   if (status != 0)
     {
       printf("sem_test: Error in thread 1 creation, status=%d\n",  status);
@@ -202,7 +205,7 @@ void sem_test(void)
       printf("sem_test: Set thread 2 priority to %d\n",  sparam.sched_priority);
     }
 
-  status = pthread_create(&waiter_thread2, &attr, waiter_func, (void*)2);
+  status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2);
   if (status != 0)
     {
       printf("sem_test: Error in thread 2 creation, status=%d\n",  status);
@@ -226,13 +229,19 @@ void sem_test(void)
       printf("sem_test: Set thread 3 priority to %d\n",  sparam.sched_priority);
     }
 
-  status = pthread_create(&poster_thread, &attr, poster_func, (void*)3);
+  status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3);
   if (status != 0)
     {
       printf("sem_test: Error in thread 3 creation, status=%d\n",  status);
     }
 
+#ifdef SDCC
+  pthread_join(waiter_thread1, &result);
+  pthread_join(waiter_thread2, &result);
+  pthread_join(poster_thread, &result);
+#else
   pthread_join(waiter_thread1, NULL);
   pthread_join(waiter_thread2, NULL);
   pthread_join(poster_thread, NULL);
+#endif
 }
diff --git a/examples/ostest/sighand.c b/examples/ostest/sighand.c
index ada7d88364b1bb3b5900d9a80847f517e5a655de..f6970deb0570a6b77d06c766e44b147df23d86e3 100644
--- a/examples/ostest/sighand.c
+++ b/examples/ostest/sighand.c
@@ -145,8 +145,10 @@ static int waiter_main(int argc, char *argv[])
       printf("waiter_main: ERROR sigaction failed, status=%d\n" , status);
     }
 
+#ifndef SDCC
   printf("waiter_main: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n",
           oact.sa_sigaction, oact.sa_flags, oact.sa_mask);
+#endif
 
   /* Take the semaphore */
 
@@ -225,7 +227,11 @@ void sighand_test(void)
   /* Then signal the waiter thread. */
 
   sigvalue.sival_int = SIGVALUE_INT;
+#ifdef CONFIG_CAN_PASS_STRUCTS
   status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue);
+#else
+  status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue.sival_ptr);
+#endif
   if (status != OK)
     {
       printf("sighand_test: ERROR sigqueue failed\n" );
diff --git a/examples/ostest/timedwait.c b/examples/ostest/timedwait.c
index af2fd2551cfa1aefa1d4111dcd2ca4665653f9af..81e7c4a61a771f64ebb8e04f876ef3960aef0f99 100644
--- a/examples/ostest/timedwait.c
+++ b/examples/ostest/timedwait.c
@@ -95,7 +95,7 @@ static void *thread_waiter(void *parameter)
     }
 
   printf("thread_waiter: Exit with status 0x12345678\n");
-  pthread_exit((void*)0x12345678);
+  pthread_exit((pthread_addr_t)0x12345678);
   return NULL;
 }
 
diff --git a/fs/Makefile b/fs/Makefile
index 36b651739e1eb321716cb07e89e21330f4e12df0..6cce1face44834f03b00305a99ed96ea6c7f12e2 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -70,7 +70,7 @@ $(BIN):	$(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/fs/fs_close.c b/fs/fs_close.c
index a6a81d25453f69d6402eec2c572e50922f7e9a99..d8195a6d4b2a1b1e365b07adeb39e6a65dec75f8 100644
--- a/fs/fs_close.c
+++ b/fs/fs_close.c
@@ -60,7 +60,7 @@
 
 int close(int fd)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
 
   /* Get the thread-specific file list */
 
@@ -73,7 +73,7 @@ int close(int fd)
 
   if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
     {
-      struct inode *inode = list->fl_files[fd].f_inode;
+      FAR struct inode *inode = list->fl_files[fd].f_inode;
       if (inode)
         {
           files_release(fd);
diff --git a/fs/fs_dup.c b/fs/fs_dup.c
index 114f4b9519fe55e3c230a287b5bb6aa912b623f9..1a012903c402090438f4d084dd63c588f3a3d806 100644
--- a/fs/fs_dup.c
+++ b/fs/fs_dup.c
@@ -69,7 +69,7 @@
 
 int dup(int fildes)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
   int fildes2;
 
   /* Get the thread-specific file list */
@@ -109,7 +109,7 @@ int dup(int fildes)
 
 int dup2(int fildes1, int fildes2)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
 
   /* Get the thread-specific file list */
 
diff --git a/fs/fs_files.c b/fs/fs_files.c
index a280f92101d55260b73bbefedf101b8e9f072946..63a3554aa1e56ee1c0e96f99db1ea8af8d6227c4 100644
--- a/fs/fs_files.c
+++ b/fs/fs_files.c
@@ -72,7 +72,7 @@
  * Private Functions
  ************************************************************/
 
-static void _files_semtake(struct filelist *list)
+static void _files_semtake(FAR struct filelist *list)
 {
   /* Take the semaphore (perhaps waiting) */
 
@@ -102,10 +102,10 @@ void files_initialize(void)
 
 /* Allocate a list of files for a new task */
 
-struct filelist *files_alloclist(void)
+FAR struct filelist *files_alloclist(void)
 {
-  struct filelist *list;
-  list = (struct filelist*)kzmalloc(sizeof(struct filelist));
+  FAR struct filelist *list;
+  list = (FAR struct filelist*)kzmalloc(sizeof(struct filelist));
   if (list)
     {
        /* Start with a reference count of one */
@@ -121,7 +121,7 @@ struct filelist *files_alloclist(void)
 
 /* Increase the reference count on a file list */
 
-int files_addreflist(struct filelist *list)
+int files_addreflist(FAR struct filelist *list)
 {
   if (list)
     {
@@ -136,7 +136,7 @@ int files_addreflist(struct filelist *list)
 
 /* Release a reference to the file list */
 
-int files_releaselist(struct filelist *list)
+int files_releaselist(FAR struct filelist *list)
 {
   int crefs;
   if (list)
@@ -159,7 +159,7 @@ int files_releaselist(struct filelist *list)
 
             for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
               {
-                struct inode *inode = list->fl_files[i].f_inode;
+                FAR struct inode *inode = list->fl_files[i].f_inode;
                 if (inode)
                   {
                     inode_release(inode);
@@ -179,9 +179,9 @@ int files_releaselist(struct filelist *list)
  * heart of dup2.
  */
 
-int files_dup(struct file *filep1, struct file *filep2)
+int files_dup(FAR struct file *filep1, FAR struct file *filep2)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
 
   if (!filep1 || !filep1->f_inode || !filep2)
     {
@@ -225,34 +225,34 @@ int files_dup(struct file *filep1, struct file *filep2)
  * the files array.
  */
 
-int files_allocate(struct inode *inode, int oflags, off_t pos)
+int files_allocate(FAR struct inode *inode, int oflags, off_t pos)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
   int i;
 
   list = sched_getfiles();
   if (list)
     {
-    _files_semtake(list);
-    for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
-      {
-        if (!list->fl_files[i].f_inode)
-          {
-             list->fl_files[i].f_oflags = oflags;
-             list->fl_files[i].f_pos    = pos;
-             list->fl_files[i].f_inode  = inode;
-             _files_semgive(list);
-             return i;
-          }
-      }
-    _files_semgive(list);
-  }
+      _files_semtake(list);
+      for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
+        {
+          if (!list->fl_files[i].f_inode)
+            {
+               list->fl_files[i].f_oflags = oflags;
+               list->fl_files[i].f_pos    = pos;
+               list->fl_files[i].f_inode  = inode;
+               _files_semgive(list);
+               return i;
+            }
+        }
+      _files_semgive(list);
+    }
   return ERROR;
 }
 
 void files_release(int filedes)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
 
   list = sched_getfiles();
   if (list)
diff --git a/fs/fs_inode.c b/fs/fs_inode.c
index db7451d3091a5e1a652d2c3061fc97f765b855d7..c6d6731903c903c02b40e5ff9b7c7d509ca948a9 100644
--- a/fs/fs_inode.c
+++ b/fs/fs_inode.c
@@ -69,7 +69,7 @@ static sem_t tree_sem;
  * Public Variables
  ************************************************************/
 
-struct inode *root_inode = NULL;
+FAR struct inode *root_inode = NULL;
 
 /************************************************************
  * Private Functions
@@ -92,7 +92,7 @@ static void _inode_semtake(void)
 #define _inode_semgive(void) sem_post(&tree_sem)
 
 static int _inode_compare(const char *fname,
-                           struct inode *node)
+                          FAR struct inode *node)
 {
   char *nname = node->i_name;
 
@@ -172,12 +172,12 @@ static const char *_inode_nextname(const char *name)
    return name;
 }
 
-static struct inode *_inode_alloc(const char *name,
-                                   struct file_operations *fops,
-                                   mode_t mode, void *private)
+static FAR struct inode *_inode_alloc(const char *name,
+                                      struct file_operations *fops,
+                                      mode_t mode, void *private)
 {
   int namelen = _inode_namelen(name);
-  struct inode *node = malloc(FSNODE_SIZE(namelen));
+  FAR struct inode *node = (FAR struct inode*)malloc(FSNODE_SIZE(namelen));
   if (node)
     {
       node->i_peer    = NULL;
@@ -192,14 +192,14 @@ static struct inode *_inode_alloc(const char *name,
   return node;
 }
 
-static struct inode *_inode_find(const char **path,
-                                  struct inode **peer,
-                                  struct inode **parent)
+static FAR struct inode *_inode_find(const char **path,
+                                     FAR struct inode **peer,
+                                     FAR struct inode **parent)
 {
-  const char      *name  = *path + 1; /* Skip over leading '/' */
-  struct inode *node  = root_inode;
-  struct inode *left  = NULL;
-  struct inode *above = NULL;
+  const char       *name  = *path + 1; /* Skip over leading '/' */
+  FAR struct inode *node  = root_inode;
+  FAR struct inode *left  = NULL;
+  FAR struct inode *above = NULL;
 
   while (node)
     {
@@ -278,9 +278,9 @@ static struct inode *_inode_find(const char **path,
   return node;
 }
 
-static void _inode_insert(struct inode *node,
-                           struct inode *peer,
-                           struct inode *parent)
+static void _inode_insert(FAR struct inode *node,
+                          FAR struct inode *peer,
+                          FAR struct inode *parent)
 {
   /* If peer is non-null, then new node simply goes to the right
    * of that peer node.
@@ -342,7 +342,7 @@ static void _inode_remove(struct inode *node,
    node->i_peer    = NULL;
 }
 
-static void _inode_free(struct inode *node)
+static void _inode_free(FAR struct inode *node)
 {
   if (node)
     {
@@ -370,7 +370,9 @@ void fs_initialize(void)
 
   /* Initialize files array (if it is used) */
 
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
   if (files_initialize != NULL)
+#endif
     {
       files_initialize();
     }
@@ -380,9 +382,9 @@ void fs_initialize(void)
  * to the inode associatged with a path.
  */
 
-struct inode *inode_find(const char *path)
+FAR struct inode *inode_find(const char *path)
 {
-  struct inode *node;
+  FAR struct inode *node;
 
   if (!*path || path[0] != '/')
     {
@@ -394,7 +396,7 @@ struct inode *inode_find(const char *path)
    */
 
   _inode_semtake();
-  node = _inode_find(&path, NULL, NULL);
+  node = _inode_find(&path, (FAR void*)NULL, (FAR void*)NULL);
   if (node) node->i_crefs++;
   _inode_semgive();
   return node;
@@ -404,7 +406,7 @@ struct inode *inode_find(const char *path)
  * descriptor is dup'ed.
  */
 
-void inode_addref(struct inode *inode)
+void inode_addref(FAR struct inode *inode)
 {
   if (inode)
     {
@@ -418,14 +420,17 @@ void inode_addref(struct inode *inode)
  * to the inode.
  */
 
-void inode_release(struct inode *node)
+void inode_release(FAR struct inode *node)
 {
   if (node)
     {
       /* Decrement the references of the inode */
 
       _inode_semtake();
-      if (node->i_crefs) node->i_crefs--;
+      if (node->i_crefs)
+        {
+          node->i_crefs--;
+        }
 
       /* If the subtree was previously deleted and the reference
        * count has decrement to zero,  then delete the inode
@@ -450,9 +455,9 @@ STATUS register_inode(const char *path,
                       struct file_operations *fops,
                       mode_t mode, void *private)
 {
-  const char      *name = path;
-  struct inode *left;
-  struct inode *parent;
+  const char       *name = path;
+  FAR struct inode *left;
+  FAR struct inode *parent;
 
   if (!*path || path[0] != '/')
     {
@@ -474,7 +479,7 @@ STATUS register_inode(const char *path,
 
   for (;;)
     {
-      struct inode *node;
+      FAR struct inode *node;
 
       /* Create a new node -- we need to know if this is the
        * the leaf node or some intermediary.  We can find this
@@ -519,10 +524,10 @@ STATUS register_inode(const char *path,
 
 STATUS unregister_inode(const char *path)
 {
-  const char      *name = path;
-  struct inode *node;
-  struct inode *left;
-  struct inode *parent;
+  const char       *name = path;
+  FAR struct inode *node;
+  FAR struct inode *left;
+  FAR struct inode *parent;
 
   if (*path && path[0] == '/')
     {
diff --git a/fs/fs_internal.h b/fs/fs_internal.h
index e8e8a33c971cc63cd7515d49556628353f7ef10c..a063335fb7aff557c1ee452bc0b48279db6931c5 100644
--- a/fs/fs_internal.h
+++ b/fs/fs_internal.h
@@ -58,10 +58,7 @@
  * Global Variables
  ************************************************************/
 
-#if CONFIG_NFILE_DESCRIPTORS >0
-extern struct file files[CONFIG_NFILE_DESCRIPTORS];
-#endif
-extern struct inode *root_inode;
+extern FAR struct inode *root_inode;
 
 /************************************************************
  * Pulblic Function Prototypes
@@ -77,23 +74,21 @@ extern "C" {
 
 /* fs_inode.c ***********************************************/
 
-EXTERN struct inode *inode_find(const char *path);
-EXTERN void inode_addref(struct inode *inode);
-EXTERN void inode_release(struct inode *inode);
+EXTERN FAR struct inode *inode_find(const char *path);
+EXTERN void inode_addref(FAR struct inode *inode);
+EXTERN void inode_release(FAR struct inode *inode);
 
 /* fs_files.c ***********************************************/
 
 #if CONFIG_NFILE_DESCRIPTORS >0
 EXTERN void weak_function files_initialize(void);
-EXTERN int  files_allocate(struct inode *inode, int oflags, off_t pos);
+EXTERN int  files_allocate(FAR struct inode *inode, int oflags, off_t pos);
 EXTERN void files_release(int filedes);
 #endif
 
 #undef EXTERN
 #if defined(__cplusplus)
 }
-#endif 
-
-
+#endif
 
 #endif /* __FS_INTERNAL_H */
diff --git a/fs/fs_ioctl.c b/fs/fs_ioctl.c
index 483a2d9299126a6fed020b55b89b4d700bb76c72..4202ce8b321e90dd6f7311f4c37c7fa1bcea0a84 100644
--- a/fs/fs_ioctl.c
+++ b/fs/fs_ioctl.c
@@ -53,14 +53,24 @@
 
 int ioctl(int fd, int req, unsigned long arg)
 {
+  FAR struct filelist *list;
   int ret = EBADF;
 
-  /* We we give a valid file descriptor? */
+  /* Get the thread-specific file list */
+
+  list = sched_getfiles();
+  if (!list)
+    {
+      *get_errno_ptr() = EMFILE;
+      return ERROR;
+    }
+
+  /* Were we give a valid file descriptor? */
 
   if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
     {
-      struct file *this_file      = &files[fd];
-      struct inode *inode         = this_file->f_inode;
+      FAR struct file *this_file = &list->fl_files[fd];
+      struct inode *inode        = this_file->f_inode;
 
       /* Is a driver registered? Does it support the ioctl method? */
 
diff --git a/fs/fs_open.c b/fs/fs_open.c
index deedd60feb598df0e9c730b4171a26747fca5dac..3703fecda2f60917d014e42aee95953077db3246 100644
--- a/fs/fs_open.c
+++ b/fs/fs_open.c
@@ -68,7 +68,7 @@
  * Public Functions
  ************************************************************/
 
-int inode_checkflags(struct inode *inode, int oflags)
+int inode_checkflags(FAR struct inode *inode, int oflags)
 {
   if (((oflags & O_RDOK) != 0 && !inode->i_ops->read) ||
       ((oflags & O_WROK) != 0 && !inode->i_ops->write))
@@ -85,7 +85,7 @@ int inode_checkflags(struct inode *inode, int oflags)
 int open(const char *path, int oflags, ...)
 {
   struct filelist *list;
-  struct inode *inode;
+  FAR struct inode *inode;
   int status;
   int fd;
 
@@ -150,7 +150,7 @@ int open(const char *path, int oflags, ...)
   status = OK;
   if (inode->i_ops && inode->i_ops->open)
     {
-      status = inode->i_ops->open(&list->fl_files[fd]);
+      status = inode->i_ops->open((FAR struct file*)&list->fl_files[fd]);
     }
 
   if (status != OK || !inode->i_ops)
diff --git a/fs/fs_read.c b/fs/fs_read.c
index a092d0db63d11bd7081eea5374feb2f39b560762..1bbcdead05af0a0dc9213b84d5a7ce85dad78a46 100644
--- a/fs/fs_read.c
+++ b/fs/fs_read.c
@@ -57,7 +57,7 @@
 
 int read(int fd, void *buf, unsigned int nbytes)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
   int ret = EBADF;
 
   /* Get the thread-specific file list */
@@ -73,23 +73,23 @@ int read(int fd, void *buf, unsigned int nbytes)
 
   if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
     {
-      struct file *this_file = &list->fl_files[fd];
+      FAR struct file *this_file = &list->fl_files[fd];
 
       /* Was this file opened for read access? */
 
       if ((this_file->f_oflags & O_RDOK) != 0)
-	{
+        {
           struct inode *inode = this_file->f_inode;
 
-	  /* Is a driver registered? Does it support the read method? */
+          /* Is a driver registered? Does it support the read method? */
 
-	  if (inode && inode->i_ops && inode->i_ops->read)
-	    {
-	      /* Yes, then let it perform the read */
+          if (inode && inode->i_ops && inode->i_ops->read)
+            {
+              /* Yes, then let it perform the read */
 
-	      ret = (int)inode->i_ops->read(this_file, (char*)buf, (size_t)nbytes);
-	    }
-	}
+              ret = (int)inode->i_ops->read(this_file, (char*)buf, (size_t)nbytes);
+            }
+        }
     }
   return ret;
 }
diff --git a/fs/fs_write.c b/fs/fs_write.c
index d85ba61e6e8768143550954016c204c2ac96ee3d..3928656ad9560b44673661fd1563e4b71cc96999 100644
--- a/fs/fs_write.c
+++ b/fs/fs_write.c
@@ -57,7 +57,7 @@
 
 int write(int fd, const void *buf, unsigned int nbytes)
 {
-  struct filelist *list;
+  FAR struct filelist *list;
   int ret = EBADF;
 
   /* Get the thread-specific file list */
@@ -73,7 +73,7 @@ int write(int fd, const void *buf, unsigned int nbytes)
 
   if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
     {
-      struct file *this_file = &list->fl_files[fd];
+      FAR struct file *this_file = &list->fl_files[fd];
 
       /* Was this file opened for write access? */
 
diff --git a/include/assert.h b/include/assert.h
index 022e343cabb0e35cba006d351fd5d61c785a545a..4222aa2d8ef2e66eed917f2b01bdbba988617e2c 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -106,8 +106,8 @@ extern "C" {
 #endif
 
 #ifdef __GNUC__
-EXTERN void   up_assert(const ubyte *fileName, int lineNum);
-EXTERN void   up_assert_code(const ubyte *fileName, int lineNum,
+EXTERN void   up_assert(FAR const ubyte *filename, int linenum);
+EXTERN void   up_assert_code(FAR const ubyte *filename, int linenum,
                              int error_code);
 #else
 EXTERN void   up_assert(void);
diff --git a/include/errno.h b/include/errno.h
index d189ccaa0814eb81358aa09adec9f12d56d945f5..6f362cfc90ec8dbc8c5c7a9b6012ac22400bd5aa 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -190,13 +190,7 @@ extern "C" {
 
 /* Return a pointer to the thread specifid errno */
 
-extern int *get_errno_ptr(void);
-
-#ifndef CONFIG_CAN_CAST_POINTERS
-/* Return the value ERROR cast to (void*) */
-
-extern void *get_errorptr(void);
-#endif
+extern FAR int *get_errno_ptr(void);
 
 #undef EXTERN
 #if defined(__cplusplus)
diff --git a/include/mqueue.h b/include/mqueue.h
index 3e54ba6e8064afea6d02f26e18c0c01d041f4bd0..7e0966d2556f57952cea1e8d0bbc1245709a2382 100644
--- a/include/mqueue.h
+++ b/include/mqueue.h
@@ -78,7 +78,7 @@ struct sigevent {
 
 /* Message queue descriptor */
 
-typedef struct mq_des *mqd_t;
+typedef FAR struct mq_des *mqd_t;
 
 /************************************************************
  * Global Variables
@@ -95,8 +95,7 @@ extern "C" {
 #define EXTERN extern
 #endif
 
-EXTERN mqd_t   mq_open(const char *mq_name,
-                  int oflags, ... );
+EXTERN mqd_t   mq_open(const char *mq_name, int oflags, ... );
 EXTERN int     mq_close(mqd_t mqdes );
 EXTERN int     mq_unlink(const char *mq_name );
 EXTERN int     mq_send(mqd_t mqdes, const void *msg,
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 5ccba7c20ebae723307f2946db4f5a5c10d2572e..11e6a96fc041895b4482952424db65306683adef 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -127,7 +127,7 @@ EXTERN void up_idle(void);
  *
  ************************************************************/
 
-EXTERN void up_initial_state(_TCB *tcb);
+EXTERN void up_initial_state(FAR _TCB *tcb);
 
 /************************************************************
  * Name: up_create_stack
@@ -150,7 +150,7 @@ EXTERN void up_initial_state(_TCB *tcb);
  *     must be allocated.
  ************************************************************/
 
-EXTERN STATUS up_create_stack(_TCB *tcb, size_t stack_size);
+EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size);
 
 /************************************************************
  * Name: up_use_stack
@@ -173,7 +173,7 @@ EXTERN STATUS up_create_stack(_TCB *tcb, size_t stack_size);
  *
  ************************************************************/
 
-EXTERN STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size);
+EXTERN STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
 
 /************************************************************
  * Name: up_release_stack
@@ -184,7 +184,7 @@ EXTERN STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size);
  *
  ************************************************************/
 
-EXTERN void up_release_stack(_TCB *dtcb);
+EXTERN void up_release_stack(FAR _TCB *dtcb);
 
 /************************************************************
  * Name: up_unblock_task
@@ -202,7 +202,7 @@ EXTERN void up_release_stack(_TCB *dtcb);
  *
  ************************************************************/
 
-EXTERN void up_unblock_task(_TCB *tcb);
+EXTERN void up_unblock_task(FAR _TCB *tcb);
 
 /************************************************************
  * Name: up_block_task
@@ -224,7 +224,7 @@ EXTERN void up_unblock_task(_TCB *tcb);
  *
  ************************************************************/
 
-EXTERN void up_block_task(_TCB *tcb, tstate_t task_state);
+EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
 
 /************************************************************
  * Name: up_release_pending
@@ -259,7 +259,7 @@ EXTERN void up_release_pending(void);
  *
  ************************************************************/
 
-EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
+EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority);
 
 /************************************************************
  * Name: _exit
@@ -314,7 +314,7 @@ EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
  *
  ************************************************************/
 
-EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
+EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
 
 /************************************************************
  * Name: up_allocate_heap
@@ -328,7 +328,7 @@ EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
  ************************************************************/
 
 #ifndef CONFIG_HEAP_BASE
-EXTERN void up_allocate_heap(void **heap_start, size_t *heap_size);
+EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
 #endif
 
 /************************************************************
@@ -401,7 +401,7 @@ EXTERN void sched_process_timer(void);
  *
  ***********************************************************/
 
-EXTERN void irq_dispatch(int irq, void *context);
+EXTERN void irq_dispatch(int irq, FAR void *context);
 
 /************************************************************
  * Debug interfaces exported by the architecture-specific
diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index b5eafe8d98e287ba0586700ae78e9afc263c4c9d..f15902171cd5716f2d67cb91e4638f819f67c423 100644
--- a/include/nuttx/compiler.h
+++ b/include/nuttx/compiler.h
@@ -44,26 +44,128 @@
  * Definitions
  ************************************************************/
 
+/* GCC-specific definitions *********************************/
+
 #ifdef __GNUC__
+
+/* GCC supports weak symbols which can be used to reduce
+ * code size because unnecessary "weak" functions can be
+ * excluded from the link.
+ */
+
+# define CONFIG_HAVE_WEAKFUNCTIONS 1
 # define weak_alias(name, aliasname) \
   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
 # define weak_function __attribute__ ((weak))
 # define weak_const_function __attribute__ ((weak, __const__))
+
+/* The noreturn attribute informs GCC that the function will
+ * not return.
+ */
+
 # define noreturn_function __attribute__ ((noreturn))
+
+/* GCC does not support the reentrant attribute */
+
 # define reentrant_function
-#elif defined(__SDCC__)
+
+/* GCC has does not use storage classes to qualify addressing */
+
+# define FAR
+# define NEAR
+
+/* Select the large, 32-bit addressing model */
+
+# undef  CONFIG_SMALL_MEMORY
+
+/* GCC supports inlined functions */
+
+# define CONFIG_HAVE_INLINE 1
+
+/* GCC supports both types double and long long */
+
+# define CONFIG_HAVE_DOUBLE 1
+# define CONFIG_HAVE_LONG_LONG 1
+
+/* Structures and unions can be assigned and passed as values */
+
+# define CONFIG_CAN_PASS_STRUCTS 1
+
+/* SDCC-specific definitions ********************************/
+
+#elif defined(SDCC)
+
+/* Disable warnings for unused function arguments */
+
 # pragma disable_warning 85
+
+/* SDCC does not support weak symbols */
+
+# undef  CONFIG_HAVE_WEAKFUNCTIONS
 # define weak_alias(name, aliasname)
 # define weak_function
 # define weak_const_function
+
+/* SDCC does not support the noreturn attribute */
+
 # define noreturn_function
+
+/* The reentrant attribute informs SDCC that the function
+ * must be reentrant.  In this case, SDCC will store input
+ * arguments on the stack to support reentrancy.
+ */
+
 # define reentrant_function __reentrant
+
+/* It is assumed that the system is build using the small
+ * data model with storage defaulting to internal RAM.
+ * The NEAR storage class can also be used to address data
+ * in internal RAM; FAR can be used to address data in
+ * external RAM.
+ */
+
+#define FAR  __xdata
+#define NEAR __data
+
+/* Select small, 16-bit address model */
+
+# define CONFIG_SMALL_MEMORY 1
+
+/* SDCC does not support inline functions */
+
+# undef  CONFIG_HAVE_INLINE
+
+/* SDCC does not support type long long or type double */
+
+# undef  CONFIG_HAVE_LONG_LONG
+# undef  CONFIG_HAVE_DOUBLE
+
+/* Structures and unions cannot be passed as values or used
+ * in assignments.
+ */
+
+# undef  CONFIG_CAN_PASS_STRUCTS
+
+/* Unknown compiler *****************************************/
+
 #else
+
+# undef  CONFIG_HAVE_WEAKFUNCTIONS
 # define weak_alias(name, aliasname)
 # define weak_function
 # define weak_const_function
 # define noreturn_function
 # define reentrant_function
+
+# define FAR
+# define NEAR
+
+# undef  CONFIG_SMALL_MEMORY
+# undef  CONFIG_HAVE_INLINE
+# undef  CONFIG_HAVE_LONG_LONG
+# undef  CONFIG_HAVE_DOUBLE
+# undef  CONFIG_CAN_PASS_STRUCTS
+
 #endif
 
 /************************************************************
diff --git a/include/nuttx/fs.h b/include/nuttx/fs.h
index 085c050ef6b94a88b72a9ec75c77e9642011980d..7e0eb8980a57cf358dd5abb0235acb4ebce7740e 100644
--- a/include/nuttx/fs.h
+++ b/include/nuttx/fs.h
@@ -60,29 +60,27 @@
 struct file;
 struct file_operations
 {
-  int     (*open)(struct file *);
-  int     (*close)(struct file *);
-//  off_t (*llseek)(struct file *, off_t, int);
-  ssize_t (*read)(struct file *, char *, size_t);
-  ssize_t (*write)(struct file *, const char *, size_t);
-//  unsigned int (*poll)(struct file *, struct poll_table_struct *);
-  int     (*ioctl)(struct file *, int, unsigned long);
+  int     (*open)(FAR struct file *);
+  int     (*close)(FAR struct file *);
+  ssize_t (*read)(FAR struct file *, char *, size_t);
+  ssize_t (*write)(FAR struct file *, const char *, size_t);
+  int     (*ioctl)(FAR struct file *, int, unsigned long);
 };
 
 /* This structure represents one inode in the Nuttx psuedo-file system */
 
 struct inode
 {
-  struct inode           *i_peer;    /* Pointer to inode at same level */
-  struct inode           *i_child;   /* Pointer to inode at lower level */
-  struct file_operations *i_ops;     /* Driver file operations for inode */
-  sint16                  i_crefs;   /* References to inode */
-  uint16                  i_flags;  /* flags for inode */
+  FAR struct inode           *i_peer;    /* Pointer to inode at same level */
+  FAR struct inode           *i_child;   /* Pointer to inode at lower level */
+  struct file_operations     *i_ops;     /* Driver file operations for inode */
+  sint16                      i_crefs;   /* References to inode */
+  uint16                      i_flags;   /* flags for inode */
 #ifdef CONFIG_FILE_MODE
-  mode_t                  i_mode;    /* Access mode flags */
+  mode_t                      i_mode;    /* Access mode flags */
 #endif
-  void                   *i_private; /* Driver private data */
-  char                    i_name[1]; /* Name of inode (variable length) */
+  FAR void                   *i_private; /* Driver private data */
+  char                        i_name[1]; /* Name of inode (variable length) */
 };
 #define FSNODE_SIZE(n) (sizeof(struct inode) + (n))
 
@@ -94,9 +92,9 @@ struct inode
 
 struct file
 {
-  int           f_oflags; /* Open mode flags */
-  off_t         f_pos;    /* File position */
-  struct inode *f_inode;  /* Driver interface */
+  int               f_oflags; /* Open mode flags */
+  off_t             f_pos;    /* File position */
+  FAR struct inode *f_inode;  /* Driver interface */
 };
 
 /* This defines a list of files indexed by the file descriptor */
@@ -119,20 +117,20 @@ struct filelist
 #if CONFIG_NFILE_STREAMS > 0
 struct file_struct
 {
-  int            fs_filedes;    /* File descriptor associated with stream */
-  mode_t         fs_oflags;     /* Open mode flags */
+  int                fs_filedes;   /* File descriptor associated with stream */
+  mode_t             fs_oflags;    /* Open mode flags */
 #if CONFIG_NUNGET_CHARS > 0
-  uint8          fs_nungotten;  /* The number of characters buffered for ungetc */
-  unsigned char  fs_ungotten[CONFIG_NUNGET_CHARS];
+  uint8              fs_nungotten; /* The number of characters buffered for ungetc */
+  unsigned char      fs_ungotten[CONFIG_NUNGET_CHARS];
 #endif
 #if CONFIG_STDIO_BUFFER_SIZE > 0
-  sem_t          fs_sem;        /* For thread safety */
-  pid_t          fs_holder;     /* Holder of sem */
-  int            fs_counts;     /* Number of times sem is held */
-  unsigned char *fs_bufstart;   /* Pointer to start of buffer */
-  unsigned char *fs_bufend;     /* Pointer to 1 past end of buffer */
-  unsigned char *fs_bufpos;     /* Current position in buffer */
-  unsigned char *fs_bufread;    /* Pointer to 1 past last buffered read char. */
+  sem_t              fs_sem;       /* For thread safety */
+  pid_t              fs_holder;    /* Holder of sem */
+  int                fs_counts;    /* Number of times sem is held */
+  FAR unsigned char *fs_bufstart;  /* Pointer to start of buffer */
+  FAR unsigned char *fs_bufend;    /* Pointer to 1 past end of buffer */
+  FAR unsigned char *fs_bufpos;    /* Current position in buffer */
+  FAR unsigned char *fs_bufread;   /* Pointer to 1 past last buffered read char. */
 #endif
 };
 
@@ -170,15 +168,15 @@ EXTERN STATUS unregister_inode(const char *path);
 
 /* fs_open.c ************************************************/
 
-EXTERN int   inode_checkflags(struct inode *inode, int oflags);
+EXTERN int   inode_checkflags(FAR struct inode *inode, int oflags);
 
 /* fs_files.c ***********************************************/
 
 #if CONFIG_NFILE_DESCRIPTORS >0
-EXTERN struct filelist *files_alloclist(void);
-EXTERN int files_addreflist(struct filelist *list);
-EXTERN int files_releaselist(struct filelist *list);
-EXTERN int files_dup(struct file *filep1, struct file *filep2);
+EXTERN FAR struct filelist *files_alloclist(void);
+EXTERN int files_addreflist(FAR struct filelist *list);
+EXTERN int files_releaselist(FAR struct filelist *list);
+EXTERN int files_dup(FAR struct file *filep1, FAR struct file *filep2);
 #endif
 
 /* lib_fopen.c **********************************************/
@@ -186,16 +184,16 @@ EXTERN int files_dup(struct file *filep1, struct file *filep2);
 /* Used by the OS to clone stdin, stdout, stderr */
 
 #if CONFIG_NFILE_STREAMS > 0
-EXTERN struct file_struct *lib_fdopen(int fd,
-                                       const char *mode,
-                                       struct filelist *flist,
-                                       struct streamlist *slist);
+EXTERN FAR struct file_struct *lib_fdopen(int fd,
+                                          const char *mode,
+                                          FAR struct filelist *flist,
+                                          FAR struct streamlist *slist);
 #endif
 
 /* lib_fflush.c *********************************************/
 
 #if CONFIG_NFILE_STREAMS > 0
-EXTERN void lib_flushall(struct streamlist *list);
+EXTERN void lib_flushall(FAR struct streamlist *list);
 #endif
 
 /* drivers **************************************************/
diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h
index 82a34c7604b11f0ec532f5a2eb11f0553a3c5b1a..a806adb1505f99119c9375d7b335cc7664de2465 100644
--- a/include/nuttx/irq.h
+++ b/include/nuttx/irq.h
@@ -60,9 +60,9 @@
 /* This struct defines the way the registers are stored */
 
 #ifndef __ASSEMBLY__
-typedef int (*xcpt_t)(int irq, void *context);
+typedef int (*xcpt_t)(int irq, FAR void *context);
 typedef int (*swint_t)(int code, int parm2, int parm3,
-                       void *context);
+                       FAR void *context);
 #endif
 
 /* Now include architecture-specific types */
diff --git a/include/nuttx/kmalloc.h b/include/nuttx/kmalloc.h
index 5a48f33d2ed12347324eec5cd68c589dd7fe7c3d..29678ebc9be4b60e671c0603693500d54d91ffdb 100644
--- a/include/nuttx/kmalloc.h
+++ b/include/nuttx/kmalloc.h
@@ -63,28 +63,28 @@ extern "C" {
 # include <stdlib.h>
 # define kmalloc(s) malloc(s)
 #else
-KMALLOC_EXTERN void  *kmalloc(size_t);
+KMALLOC_EXTERN FAR void  *kmalloc(size_t);
 #endif
 
 #ifndef CONFIG_ARCH_KZMALLOC
 # include <stdlib.h>
 # define kzmalloc(s) zalloc(s)
 #else
-KMALLOC_EXTERN void  *kzalloc(size_t);
+KMALLOC_EXTERN FAR void  *kzalloc(size_t);
 #endif
 
 #ifndef CONFIG_ARCH_KFREE
 # include <stdlib.h>
 # define kfree(p) free(p)
 #else
-KMALLOC_EXTERN void   kfree(void*);
+KMALLOC_EXTERN void   kfree(FAR void*);
 #endif
 
 /* Functions defined in os_list.c ***************************/
 
 /* Handles memory freed from an interrupt handler */
 
-KMALLOC_EXTERN void sched_free(void *address);
+KMALLOC_EXTERN void sched_free(FAR void *address);
 
 #undef KMALLOC_EXTERN
 #if defined(__cplusplus)
diff --git a/include/nuttx/lib.h b/include/nuttx/lib.h
index 52f506897b6a4f45efbae4c95ab63e030f99fe54..cca174aa3fd40e019219023a8ddbe7be599f371a 100644
--- a/include/nuttx/lib.h
+++ b/include/nuttx/lib.h
@@ -64,11 +64,11 @@ extern "C" {
 
 /* Functions contained in lib_init.c ************************/
 
-EXTERN void weak_function  lib_initialize(void);
+EXTERN void weak_function     lib_initialize(void);
 #if CONFIG_NFILE_STREAMS > 0
-EXTERN struct streamlist *lib_alloclist(void);
-EXTERN void                lib_addreflist(struct streamlist *list);
-EXTERN void                lib_releaselist(struct streamlist *list);
+EXTERN FAR struct streamlist *lib_alloclist(void);
+EXTERN void                   lib_addreflist(FAR struct streamlist *list);
+EXTERN void                   lib_releaselist(FAR struct streamlist *list);
 #endif
 
 #undef EXTERN
diff --git a/include/nuttx/os_external.h b/include/nuttx/os_external.h
index 6d96b5afb47891330a592f1f0ddf9212d3a13f4e..1d475d84e2e005f29d74b46486d4b15a2e822b90 100644
--- a/include/nuttx/os_external.h
+++ b/include/nuttx/os_external.h
@@ -75,7 +75,7 @@ EXTERN void   os_start(void); /* OS entry point called by boot logic */
 
 /* Functions contained in mm_init.c *************************/
 
-EXTERN void   mm_initialize(void *heap_start, size_t heap_size);
+EXTERN void   mm_initialize(FAR void *heap_start, size_t heap_size);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/include/pthread.h b/include/pthread.h
index 12f0d53651f544149a12d77f89dbe0adc23ebeac..ad907cf552002d3778031d813360889a759a78b1 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -41,6 +41,7 @@
  ************************************************************/
 
 #include <nuttx/config.h>   /* Default settings */
+#include <nuttx/compiler.h> /* Compiler settings */
 #include <sys/types.h>      /* Needed for general types */
 #include <semaphore.h>      /* Needed for sem_t */
 #include <time.h>           /* Needed for struct timespec */
@@ -85,11 +86,7 @@
 
 /* Thread return value when a pthread is canceled */
 
-#ifdef CONFIG_CAN_CAST_POINTERS
-# define PTHREAD_CANCELED        ((void*)ERROR)
-#else
-# define PTHREAD_CANCELED        ((void*)pthread_create)
-#endif
+# define PTHREAD_CANCELED        ((FAR void*)ERROR)
 
 /************************************************************
  * Global Type Declarations
@@ -107,7 +104,7 @@ extern "C" {
  *----------------------------------------------------------*/
 
 typedef int             pthread_key_t;
-typedef void           *pthread_addr_t;
+typedef FAR void       *pthread_addr_t;
 typedef pthread_addr_t  any_t;
 
 typedef pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
@@ -115,10 +112,10 @@ typedef pthread_startroutine_t	pthread_func_t;
 
 struct pthread_addr_s
 {
-  unsigned long stacksize;    /* Size of the stack allocated for the pthead */
-  short         priority;     /* Priority of the pthread */
-  ubyte         policy;       /* Pthread scheduler policy */
-  ubyte         inheritsched; /* Inherit parent prio/policy? */
+  size_t stacksize;    /* Size of the stack allocated for the pthead */
+  short  priority;     /* Priority of the pthread */
+  ubyte  policy;       /* Pthread scheduler policy */
+  ubyte  inheritsched; /* Inherit parent prio/policy? */
 };
 typedef struct pthread_addr_s pthread_attr_t;
 
@@ -173,8 +170,10 @@ EXTERN int pthread_attr_destroy(pthread_attr_t *attr);
  * Set or obtain the default scheduling algorithm
  *----------------------------------------------------------*/
 
-EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
-EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);
+EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr,
+                                       int policy);
+EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr,
+                                       int *policy);
 EXTERN int pthread_attr_setschedparam(pthread_attr_t *attr,
 				      const struct sched_param *param);
 EXTERN int pthread_attr_getschedparam(pthread_attr_t *attr,
@@ -188,8 +187,10 @@ EXTERN int pthread_attr_getinheritsched(const pthread_attr_t *attr,
  * Set or obtain the default stack size
  *----------------------------------------------------------*/
 
-EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr, long stacksize);
-EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
+EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr,
+                                     long stacksize);
+EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr,
+                                     long *stackaddr);
 
 /*----------------------------------------------------------*
  * To create a thread object and runnable thread, a routine
@@ -200,7 +201,8 @@ EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
  * specify details about the kind of thread being created.
  *----------------------------------------------------------*/
 
-EXTERN int pthread_create(pthread_t *thread, pthread_attr_t *attr,
+EXTERN int pthread_create(pthread_t *thread,
+                          pthread_attr_t *attr,
 			  pthread_startroutine_t startRoutine,
 			  pthread_addr_t arg);
 
@@ -216,7 +218,7 @@ EXTERN int pthread_detach(pthread_t thread);
  * execution of another thread.
  *----------------------------------------------------------*/
 
-EXTERN void pthread_exit(pthread_addr_t pvValue) noreturn_function;
+EXTERN void pthread_exit(pthread_addr_t value) noreturn_function;
 EXTERN int  pthread_cancel(pthread_t thread);
 EXTERN int  pthread_setcancelstate(int state, int *oldstate);
 EXTERN void pthread_testcancel(void);
@@ -226,7 +228,8 @@ EXTERN void pthread_testcancel(void);
  * the return value of the thread.
  *----------------------------------------------------------*/
 
-EXTERN int pthread_join(pthread_t thread, pthread_addr_t *ppvValue);
+EXTERN int pthread_join(pthread_t thread,
+                        pthread_addr_t *value);
 
 /*----------------------------------------------------------*
  * A thread may tell the scheduler that its processor can be
@@ -245,7 +248,8 @@ EXTERN void pthread_yield(void);
  * Thread scheduling parameters
  *----------------------------------------------------------*/
 
-EXTERN int pthread_getschedparam(pthread_t thread, int *policy,
+EXTERN int pthread_getschedparam(pthread_t thread,
+                                 int *policy,
 				 struct sched_param *param);
 EXTERN int pthread_setschedparam(pthread_t thread, int policy,
 				 const struct sched_param *param);
@@ -255,9 +259,9 @@ EXTERN int pthread_setschedparam(pthread_t thread, int policy,
  *----------------------------------------------------------*/
 
 EXTERN int pthread_key_create(pthread_key_t *key,
-			      void (*destructor)(void*));
-EXTERN int pthread_setspecific(pthread_key_t key, void *value);
-EXTERN void *pthread_getspecific(pthread_key_t key);
+			      FAR void (*destructor)(FAR void*));
+EXTERN int pthread_setspecific(pthread_key_t key, FAR void *value);
+EXTERN FAR void *pthread_getspecific(pthread_key_t key);
 EXTERN int pthread_key_delete(pthread_key_t key);
 
 /*----------------------------------------------------------*
@@ -294,7 +298,8 @@ EXTERN int pthread_condattr_destroy(pthread_condattr_t *attr);
  * A thread can create and delete condition variables.
  *----------------------------------------------------------*/
 
-EXTERN int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
+EXTERN int pthread_cond_init(pthread_cond_t *cond,
+                             pthread_condattr_t *attr);
 EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
 
 /*----------------------------------------------------------*
@@ -302,21 +307,23 @@ EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
  *----------------------------------------------------------*/
 
 EXTERN int pthread_cond_broadcast(pthread_cond_t *cond);
-EXTERN int pthread_cond_signal(pthread_cond_t *dond);
+EXTERN int pthread_cond_signal(pthread_cond_t *cond);
 
 /*----------------------------------------------------------*
  * A thread can wait for a condition variable to be signalled
  * or broadcast.
  *----------------------------------------------------------*/
 
-EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
+EXTERN int pthread_cond_wait(pthread_cond_t *cond,
+                             pthread_mutex_t *mutex);
 
 /*----------------------------------------------------------*
  * A thread can perform a timed wait on a condition variable.
  *----------------------------------------------------------*/
 
-EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
-				  const struct timespec *abstime);
+EXTERN int pthread_cond_timedwait(pthread_cond_t *cond,
+                                  pthread_mutex_t *mutex,
+                                  const struct timespec *abstime);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/include/queue.h b/include/queue.h
index 17f4ddec02b91b4d5fe7bae6d0313ce10f2ff80f..9e45672df3cef959d92dc909c7879ed56180f388 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -58,25 +58,28 @@
 
 struct sq_entry_s
 {
-  struct sq_entry_s *flink;
+  FAR struct sq_entry_s *flink;
 };
 typedef struct sq_entry_s sq_entry_t;
 
 struct dq_entry_s
 {
-  struct dq_entry_s *flink, *blink;
+  FAR struct dq_entry_s *flink;
+  FAR struct dq_entry_s *blink;
 };
 typedef struct dq_entry_s dq_entry_t;
 
 struct sq_queue_s
 {
-  sq_entry_t *head, *tail;
+  FAR sq_entry_t *head;
+  FAR sq_entry_t *tail;
 };
 typedef struct sq_queue_s  sq_queue_t;
 
 struct dq_queue_s
 {
-  dq_entry_t *head, *tail;
+  FAR dq_entry_t *head;
+  FAR dq_entry_t *tail;
 };
 typedef struct dq_queue_s dq_queue_t;
 
@@ -91,23 +94,24 @@ extern "C" {
 #define EXTERN extern
 #endif
 
-EXTERN void        sq_addfirst(sq_entry_t *node, sq_queue_t *queue);
-EXTERN void        dq_addfirst(dq_entry_t *node, dq_queue_t *queue);
-EXTERN void        sq_addlast(sq_entry_t *node, sq_queue_t *queue);
-EXTERN void        dq_addlast(dq_entry_t *node, dq_queue_t *queue);
-EXTERN void        sq_addafter(sq_entry_t *prev, sq_entry_t *node,
-                               sq_queue_t *queue);
-EXTERN void        dq_addafter(dq_entry_t *prev, dq_entry_t *node,
-                               dq_queue_t *queue);
-EXTERN void        dq_addbefore(dq_entry_t *next, dq_entry_t *node,
-                                dq_queue_t *queue);
-EXTERN sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue);
-EXTERN void        sq_rem(sq_entry_t *node, sq_queue_t *queue);
-EXTERN void        dq_rem(dq_entry_t *node, dq_queue_t *queue);
-EXTERN sq_entry_t *sq_remlast(sq_queue_t *queue);
-EXTERN dq_entry_t *dq_remlast(dq_queue_t *queue);
-EXTERN sq_entry_t *sq_remfirst(sq_queue_t *queue);
-EXTERN dq_entry_t *dq_remfirst(dq_queue_t *queue);
+EXTERN void  sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue);
+EXTERN void  dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue);
+EXTERN void  sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue);
+EXTERN void  dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue);
+EXTERN void  sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
+                         sq_queue_t *queue);
+EXTERN void  dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
+                         dq_queue_t *queue);
+EXTERN void  dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
+                          dq_queue_t *queue);
+
+EXTERN FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue);
+EXTERN void            sq_rem(FAR sq_entry_t *node, sq_queue_t *queue);
+EXTERN void            dq_rem(FAR dq_entry_t *node, dq_queue_t *queue);
+EXTERN FAR sq_entry_t *sq_remlast(sq_queue_t *queue);
+EXTERN FAR dq_entry_t *dq_remlast(dq_queue_t *queue);
+EXTERN FAR sq_entry_t *sq_remfirst(sq_queue_t *queue);
+EXTERN FAR dq_entry_t *dq_remfirst(dq_queue_t *queue);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/include/sched.h b/include/sched.h
index 4266eb9c0a2af440dbdf0dfd49fa768f5fd016b8..79d3b2f1dbf21c9e573f7cc666dbcd40e6310c5c 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -147,7 +147,8 @@ struct _TCB
 {
   /* Fields used to support list management ***************************/
 
-  struct _TCB *flink, *blink;      /* link in DQ of TCBs              */
+  FAR struct _TCB *flink;         /* link in DQ of TCBs               */
+  FAR struct _TCB *blink;
 
   /* Task Management Fields *******************************************/
 
@@ -159,7 +160,7 @@ struct _TCB
   tstate_t task_state;            /* Current state of the thread      */
   uint16   flags;                 /* Misc. general status flags       */
   sint16   lockcount;             /* 0=preemptable (not-locked)       */
-  void    *joininfo;              /* Detach-able info to support join */
+  FAR void *joininfo;             /* Detach-able info to support join */
 #if CONFIG_RR_INTERVAL > 0
   int      timeslice;             /* RR timeslice interval remaining  */
 #endif
@@ -167,27 +168,27 @@ struct _TCB
   /* Values needed to restart a task **********************************/
 
   ubyte    init_priority;         /* Initial priority of the task     */
-  char    *argv[NUM_TASK_ARGS+1]; /* Name + start-up parameters       */
+  FAR char *argv[NUM_TASK_ARGS+1]; /* Name + start-up parameters      */
 
   /* Stack-Related Fields *********************************************/
 
   size_t  adj_stack_size;         /* Stack size after adjustment      */
                                   /* for hardware, processor, etc.    */
                                   /* (for debug purposes only)        */
-  void   *stack_alloc_ptr;        /* Pointer to allocated stack       */
+  FAR void *stack_alloc_ptr;      /* Pointer to allocated stack       */
                                   /* Need to deallocate stack         */
-  void   *adj_stack_ptr;          /* Adjusted StatckAllocPtr for HW   */
+  FAR void *adj_stack_ptr;        /* Adjusted StatckAllocPtr for HW   */
                                   /* The initial stack pointer value  */
 
   /* POSIX thread Specific Data ***************************************/
 
 #if CONFIG_NPTHREAD_KEYS > 0
-  void   *pthread_data[CONFIG_NPTHREAD_KEYS];
+  FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
 #endif
 
   /* POSIX Semaphore Control Fields ***********************************/
 
-  sem_t  *waitsem;                /* Semaphore ID waiting on          */
+  sem_t *waitsem;                 /* Semaphore ID waiting on          */
 
   /* POSIX Signal Control Fields **************************************/
 
@@ -202,7 +203,7 @@ struct _TCB
   /* POSIX Named Message Queue Fields *********************************/
 
   sq_queue_t msgdesq;             /* List of opened message queues    */
-  msgq_t    *msgwaitq;            /* Waiting for this message queue   */
+  FAR msgq_t *msgwaitq;           /* Waiting for this message queue   */
 
   /* Library related fields *******************************************/
 
@@ -211,11 +212,11 @@ struct _TCB
   /* File system support **********************************************/
 
 #if CONFIG_NFILE_DESCRIPTORS > 0
-  struct filelist *filelist;     /* Maps file descriptor to file     */
+  FAR struct filelist *filelist;  /* Maps file descriptor to file     */
 #endif
 
 #if CONFIG_NFILE_STREAMS > 0
-  struct streamlist *streams;    /* Holds C buffered I/O info        */
+  FAR struct streamlist *streams; /* Holds C buffered I/O info        */
 #endif
 
   /* State save areas *************************************************/
@@ -246,29 +247,31 @@ extern "C" {
 
 /* Task Control Interfaces (non-standard) */
 
-EXTERN STATUS  task_init(_TCB *tcb , char *name, int priority,
-                         uint32 *stack, uint32 stack_size, main_t entry,
-                         char *arg1, char *arg2, char *arg3, char *arg4);
-EXTERN STATUS  task_activate(_TCB *tcb);
-EXTERN int     task_create(char *name, int priority, int stack_size, main_t main,
-                           char *arg1, char *arg2, char *arg3, char *arg4);
+EXTERN STATUS  task_init(FAR _TCB *tcb, const char *name, int priority,
+                         FAR uint32 *stack, uint32 stack_size, main_t entry,
+                         FAR char *arg1, FAR char *arg2,
+                         FAR char *arg3, FAR char *arg4);
+EXTERN STATUS  task_activate(FAR _TCB *tcb);
+EXTERN int     task_create(const char *name, int priority, int stack_size, main_t main,
+                           FAR char *arg1, FAR char *arg2,
+                           FAR char *arg3, FAR char *arg4);
 EXTERN STATUS  task_delete(pid_t pid);
 EXTERN STATUS  task_restart(pid_t pid);
 
 /* Task Scheduling Interfaces (based on POSIX APIs) */
 
 EXTERN int     sched_setparam(pid_t pid,
-			      const struct sched_param * param);
+                              const struct sched_param *param);
 EXTERN int     sched_getparam(pid_t pid,
-			      struct sched_param * param);
+                              struct sched_param *param);
 EXTERN int     sched_setscheduler(pid_t pid, int policy,
-				  const struct sched_param * param);
+                                  const struct sched_param *param);
 EXTERN int     sched_getscheduler(pid_t pid);
 EXTERN int     sched_yield(void);
 EXTERN int     sched_get_priority_max(int policy);
 EXTERN int     sched_get_priority_min(int policy);
 EXTERN int     sched_rr_get_interval(pid_t pid,
-				     struct timespec * interval);
+                                     struct timespec *interval);
 
 /* Task Switching Interfaces (non-standard) */
 
@@ -282,9 +285,9 @@ EXTERN sint32  sched_lockcount(void);
 
 #ifdef CONFIG_SCHED_INSTRUMENTATION
 
-EXTERN void sched_note_start(_TCB *tcb );
-EXTERN void sched_note_stop(_TCB *tcb );
-EXTERN void sched_note_switch(_TCB *pFromTcb, _TCB *pToTcb);
+EXTERN void sched_note_start(FAR _TCB *tcb );
+EXTERN void sched_note_stop(FAR _TCB *tcb );
+EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
 
 #else
 # define sched_note_start(t)
@@ -295,9 +298,9 @@ EXTERN void sched_note_switch(_TCB *pFromTcb, _TCB *pToTcb);
 /* File system helpers */
 
 #if CONFIG_NFILE_DESCRIPTORS > 0
-EXTERN struct filelist *sched_getfiles(void);
+EXTERN FAR struct filelist *sched_getfiles(void);
 #if CONFIG_NFILE_STREAMS > 0
-EXTERN struct streamlist *sched_getstreams(void);
+EXTERN FAR struct streamlist *sched_getstreams(void);
 #endif /* CONFIG_NFILE_STREAMS */
 #endif /* CONFIG_NFILE_DESCRIPTORS */
 
diff --git a/include/semaphore.h b/include/semaphore.h
index 92ac7ab8987d9a498c2470ca95e06f582d55a37e..f23435a1a1237d5e9d5fd461ee4e4a540646b559 100644
--- a/include/semaphore.h
+++ b/include/semaphore.h
@@ -84,15 +84,15 @@ typedef struct sem_s sem_t;
 
 /* Counting Semaphore Interfaces (based on POSIX APIs) */
 
-EXTERN int     sem_init(sem_t *sem, int pshared, unsigned int value);
-EXTERN int     sem_destroy(sem_t *sem);
-EXTERN sem_t  *sem_open(const char *name, int oflag, ...);
-EXTERN int     sem_close(sem_t *sem);
-EXTERN int     sem_unlink(const char *name);
-EXTERN int     sem_wait(sem_t *sem);
-EXTERN int     sem_trywait(sem_t *sem);
-EXTERN int     sem_post(sem_t *sem);
-EXTERN int     sem_getvalue(sem_t *sem, int *sval);
+EXTERN int        sem_init(sem_t *sem, int pshared, unsigned int value);
+EXTERN int        sem_destroy(sem_t *sem);
+EXTERN FAR sem_t *sem_open(const char *name, int oflag, ...);
+EXTERN int        sem_close(FAR sem_t *sem);
+EXTERN int        sem_unlink(const char *name);
+EXTERN int        sem_wait(sem_t *sem);
+EXTERN int        sem_trywait(sem_t *sem);
+EXTERN int        sem_post(sem_t *sem);
+EXTERN int        sem_getvalue(sem_t *sem, int *sval);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/include/signal.h b/include/signal.h
index 4ec153b51943585323cf32294aa367d0a61b70eb..df8fe214d26c42d54a3d49a725f661b371b3eaa6 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -41,6 +41,7 @@
  ************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/compiler.h>
 #include <time.h>      /* Needed for struct timespec */
 #include <sys/types.h> /* Needed for, e.g., sigset_t */
 
@@ -123,7 +124,7 @@ struct sigaction
   union
   {
     void (*_sa_handler)(int);
-    void (*_sa_sigaction)(int, siginfo_t *, void *);
+    void (*_sa_sigaction)(int, FAR siginfo_t *, FAR void *);
   } sa_u;
   sigset_t         sa_mask;
   int              sa_flags;
@@ -155,7 +156,7 @@ EXTERN int sigaction(int sig,
 		     const struct sigaction *act,
 		     struct sigaction *oact);
 EXTERN int sigprocmask(int how, const sigset_t *set,
-		       sigset_t *oset);
+                       sigset_t *oset);
 EXTERN int sigpending(sigset_t *set);
 EXTERN int sigsuspend(const sigset_t *sigmask);
 EXTERN int sigwaitinfo(const sigset_t *set,
diff --git a/include/stdio.h b/include/stdio.h
index 883e32fc48517f6b28c99ce8795fe6060b7cabaf..8b9a7e28e4741bb246c1781d5cfb44b6a5eca1e3 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -129,12 +129,12 @@
 
 struct _dirent
 {
-  char *d_name;               /* name of directory entry */
+  FAR char *d_name;           /* name of directory entry */
 };
 struct dirent
 {
-  char *d_name;               /* A pointer to szName */
-  char szName[NAME_MAX+1];    /* name of the directory entry */
+  FAR char *d_name;           /* A pointer to d_szname */
+  char d_szname[NAME_MAX+1];  /* name of the directory entry */
 };
 
 typedef struct
@@ -147,7 +147,7 @@ typedef struct
 {
   unsigned long inode;
   int           generation;
-  char         *fileName;
+  FAR char     *filename;
 } HANDLE_TO_NAME_IOCTL;
 
 struct stat
@@ -186,7 +186,7 @@ struct statfs
 
 /* Streams */
 
-typedef struct file_struct FILE;
+typedef FAR struct file_struct FILE;
 
 typedef void DIR;
 
@@ -239,22 +239,22 @@ EXTERN int    close(int fd);
 EXTERN int    closedir(DIR *dirp);
 EXTERN int    creat(const char *path, mode_t mode);
 EXTERN FILE  *fdopen(int fd, const char *type);
-EXTERN int    fstat(int fd, struct stat *buf);
-EXTERN char  *getcwd(char *buf, size_t size);
+EXTERN int    fstat(int fd, FAR struct stat *buf);
+EXTERN char  *getcwd(FAR char *buf, size_t size);
 EXTERN int    ioctl(int fd, int req, unsigned long arg);
 EXTERN off_t  lseek(int fd, off_t offset, int whence);
 EXTERN int    mkdir(const char *path, mode_t mode);
-EXTERN int    open( const char *path, int oflag, ... );
+EXTERN int    open(const char *path, int oflag, ...);
 EXTERN DIR   *opendir(const char *path);
 EXTERN int    read(int fd, void *buf, unsigned int nbytes);
-EXTERN struct _dirent *readdir(DIR *dirp);
-EXTERN int    readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
-EXTERN void   rewinddir(DIR *dirp);
+EXTERN struct _dirent *readdir(FAR DIR *dirp);
+EXTERN int    readdir_r(FAR DIR *dirp, struct dirent *entry, FAR struct dirent **result);
+EXTERN void   rewinddir(FAR DIR *dirp);
 EXTERN int    rmdir(const char *path);
-EXTERN void   seekdir(DIR *dirp, int loc);
-EXTERN int    stat(const char *path, struct stat *buf);
-EXTERN int    statfs(const char *path, struct statfs *buf);
-EXTERN int    telldir(DIR *dirp);
+EXTERN void   seekdir(FAR DIR *dirp, int loc);
+EXTERN int    stat(const char *path, FAR struct stat *buf);
+EXTERN int    statfs(const char *path, FAR struct statfs *buf);
+EXTERN int    telldir(FAR DIR *dirp);
 EXTERN int    unlink(const char *path);
 EXTERN int    write(int fd, const void *buf, unsigned int nbytes);
 
diff --git a/include/stdlib.h b/include/stdlib.h
index ba4f2b502a15f3ea9e8dbe9fc993127baf5e80f6..4a9f2ef0d6f52c14eeadc792a305d6279d46436a 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -83,30 +83,40 @@ extern "C" {
 #endif
 
 /* Random number generation */
-EXTERN void   srand(unsigned int seed);
-EXTERN int    rand(void);
+
+EXTERN void      srand(unsigned int seed);
+EXTERN int       rand(void);
 
 /* Environment variable support */
-EXTERN char  *getenv(const char *name);
+
+EXTERN char     *getenv(const char *name);
 
 /* Process exit functions */
-EXTERN void   exit(int status);
-EXTERN void   abort(void);
-EXTERN int    atexit(void (*func)(void));
+
+EXTERN void      exit(int status);
+EXTERN void      abort(void);
+EXTERN int       atexit(void (*func)(void));
 
 /* String to binary conversions */
-#define atoi(nptr) strtol((nptr), (char**)NULL, 10)
-EXTERN long   strtol(const char *, char **, int);
-EXTERN double_t strtod(const char *, char **);
+
+#define atoi(nptr) strtol((nptr), (FAR char**)NULL, 10)
+EXTERN long      strtol(const char *, char **, int);
+EXTERN double_t  strtod(const char *, char **);
 
 /* Memory Management */
-EXTERN void  *malloc(size_t);
-EXTERN void   free(void*);
-EXTERN void  *realloc(void*, size_t);
-EXTERN void  *memalign(size_t, size_t);
-EXTERN void  *zalloc(size_t);
-EXTERN void  *calloc(size_t, size_t);
+
+EXTERN FAR void  *malloc(size_t);
+EXTERN void       free(FAR void*);
+EXTERN FAR void  *realloc(FAR void*, size_t);
+EXTERN FAR void  *memalign(size_t, size_t);
+EXTERN FAR void  *zalloc(size_t);
+EXTERN FAR void  *calloc(size_t, size_t);
+
+#ifdef CONFIG_CAN_PASS_STRUCTS
 EXTERN struct mallinfo mallinfo(void);
+#else
+EXTERN int        mallinfo(struct mallinfo *info);
+#endif
 
 #undef EXTERN
 #if defined(__cplusplus)
diff --git a/include/string.h b/include/string.h
index e63895188285d1f7a522ed327bfdbeb739ea87a2..0c8bd59b792bea955df7a35842f26a0d5073d647 100644
--- a/include/string.h
+++ b/include/string.h
@@ -60,7 +60,7 @@ extern "C" {
 #endif
 
 EXTERN char  *strchr(const char *s, int c);
-EXTERN char  *strdup(const char *s);
+EXTERN FAR char *strdup(const char *s);
 EXTERN char  *strerror(int);
 EXTERN size_t strlen(const char *);
 EXTERN char  *strncat(char *, const char *, size_t);
@@ -74,7 +74,7 @@ EXTERN char  *strrchr(const char *, int);
 EXTERN size_t strspn(const char *, const char *);
 EXTERN size_t strcspn(const char *, const char *);
 EXTERN char  *strstr(const char *, const char *);
-EXTERN char  *strtok(char *, const char *);
+EXTERN char  *strtok(FAR char *, const char *);
 
 EXTERN void  *memset(void *s, int c, size_t n);
 EXTERN void  *memcpy(void *dest, const void *src, size_t n);
diff --git a/include/unistd.h b/include/unistd.h
index e6c787ecc9f5ea229edee283b771bab6d17918da..faf50e3a365e53e931fa87b13965f0b96e50c9e3 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -67,7 +67,7 @@ extern "C" {
 
 /* Task Control Interfaces (based on ANSII APIs) */
 
-EXTERN pid_t getpid( void );
+EXTERN pid_t getpid(void);
 EXTERN void _exit(int status) noreturn_function;
 EXTERN unsigned int sleep(unsigned int seconds);
 EXTERN void usleep(unsigned long usec);
diff --git a/include/wdog.h b/include/wdog.h
index a1065eaae1ef852ed58876fd153cd647ccd3d009..fb45cb6a2a4ee093177856060c9f0c00be337304 100644
--- a/include/wdog.h
+++ b/include/wdog.h
@@ -80,7 +80,7 @@ typedef void (*wdentry_t)(int argc, uint32 arg1, ...);
 
 /* Watchdog 'handle' */
 
-typedef struct wdog_s *WDOG_ID;
+typedef FAR struct wdog_s *WDOG_ID;
 
 /************************************************************
  * Global Variables
diff --git a/lib/Makefile b/lib/Makefile
index 361c0bb63c5496031dcf74db6b6e80c7d4b89805..c05b9e96d66ec446f80f70dc7a5fb29b146be82a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -91,7 +91,7 @@ $(BIN):	$(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/lib/dq_addafter.c b/lib/dq_addafter.c
index 5533d57a1ccc02ea42f4ccea1af0aef3daf15f8c..6be30a50106642dfaef3ba474a8f5cdd169f9fe9 100644
--- a/lib/dq_addafter.c
+++ b/lib/dq_addafter.c
@@ -56,7 +56,7 @@
  *
  ************************************************************/
 
-void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
+void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
                  dq_queue_t *queue)
 {
   if (!queue->head || prev == queue->tail)
@@ -65,10 +65,10 @@ void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
     }
   else
     {
-      dq_entry_t *next = prev->flink;
-      node->blink      = prev;
-      node->flink      = next;
-      next->blink      = node;
-      prev->flink      = node;
+      FAR dq_entry_t *next = prev->flink;
+      node->blink = prev;
+      node->flink = next;
+      next->blink = node;
+      prev->flink = node;
     }
 }
diff --git a/lib/dq_addbefore.c b/lib/dq_addbefore.c
index 916a7db616df2de48ce19dd7023d9126ec639791..99df055741527f70f7e80325cd9501db4c6d3f55 100644
--- a/lib/dq_addbefore.c
+++ b/lib/dq_addbefore.c
@@ -55,7 +55,7 @@
  *
  ************************************************************/
 
-void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
+void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
                   dq_queue_t *queue)
 {
   if (!queue->head || next == queue->head)
@@ -64,10 +64,10 @@ void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
     }
   else
     {
-      dq_entry_t *prev = next->blink;
-      node->flink      = next;
-      node->blink      = prev;
-      prev->flink      = node;
-      next->blink      = node;
+      FAR dq_entry_t *prev = next->blink;
+      node->flink = next;
+      node->blink = prev;
+      prev->flink = node;
+      next->blink = node;
     }
 }
diff --git a/lib/dq_addfirst.c b/lib/dq_addfirst.c
index a11b1f8c3f75bac25c0e7503c1b5051a543d08ef..d73f49db19f5a0353ec9bf486b4adc2d2425edcc 100644
--- a/lib/dq_addfirst.c
+++ b/lib/dq_addfirst.c
@@ -55,7 +55,7 @@
  *
  ************************************************************/
 
-void dq_addfirst(dq_entry_t *node, dq_queue_t *queue)
+void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue)
 {
   node->blink = NULL;
   node->flink = queue->head;
@@ -71,3 +71,4 @@ void dq_addfirst(dq_entry_t *node, dq_queue_t *queue)
       queue->head = node;
     }
 }
+
diff --git a/lib/dq_addlast.c b/lib/dq_addlast.c
index 85c6c72a933f462fa69486f4f6b79de7c0af9eac..8d7225682e5ad48c636fe19b65e5bb8455b39d19 100644
--- a/lib/dq_addlast.c
+++ b/lib/dq_addlast.c
@@ -55,7 +55,7 @@
  *
  ************************************************************/
 
-void dq_addlast(dq_entry_t *node, dq_queue_t *queue)
+void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue)
 {
   node->flink = NULL;
   node->blink = queue->tail;
@@ -71,3 +71,4 @@ void dq_addlast(dq_entry_t *node, dq_queue_t *queue)
       queue->tail        = node;
     }
 }
+
diff --git a/lib/dq_rem.c b/lib/dq_rem.c
index d78ac8b6d8f702abae50fafa4bd40ef0ade5b03c..17f2b8622dc154adf94c4b20388017cbb8214513 100644
--- a/lib/dq_rem.c
+++ b/lib/dq_rem.c
@@ -55,10 +55,10 @@
  *
  ************************************************************/
 
-void dq_rem(dq_entry_t *node, dq_queue_t *queue)
+void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue)
 {
-  dq_entry_t *prev = node->blink;
-  dq_entry_t *next = node->flink;
+  FAR dq_entry_t *prev = node->blink;
+  FAR dq_entry_t *next = node->flink;
 
   if (!prev)
     {
@@ -81,3 +81,4 @@ void dq_rem(dq_entry_t *node, dq_queue_t *queue)
   node->flink = NULL;
   node->blink = NULL;
 }
+
diff --git a/lib/dq_remfirst.c b/lib/dq_remfirst.c
index 0c7381c7795a8caf99df7d9a97d20bb0404f82c7..ed64fe268237980182637ce56b53bf0ea3a5e50f 100644
--- a/lib/dq_remfirst.c
+++ b/lib/dq_remfirst.c
@@ -55,13 +55,13 @@
  *
  ************************************************************/
 
-dq_entry_t *dq_remfirst(dq_queue_t *queue)
+FAR dq_entry_t *dq_remfirst(dq_queue_t *queue)
 {
-  dq_entry_t *ret = queue->head;
+  FAR dq_entry_t *ret = queue->head;
 
   if (ret)
     {
-      dq_entry_t *next = ret->flink;
+      FAR dq_entry_t *next = ret->flink;
       if (!next)
         {
           queue->head = NULL;
@@ -79,3 +79,4 @@ dq_entry_t *dq_remfirst(dq_queue_t *queue)
 
   return ret;
 }
+
diff --git a/lib/dq_remlast.c b/lib/dq_remlast.c
index 47642602126e331732d9bade976ecc80ba96882b..812e1f70192653a699e03419eb12b4ab0b6d75bf 100644
--- a/lib/dq_remlast.c
+++ b/lib/dq_remlast.c
@@ -55,13 +55,13 @@
  *
  ************************************************************/
 
-dq_entry_t *dq_remlast(dq_queue_t *queue)
+FAR dq_entry_t *dq_remlast(dq_queue_t *queue)
 {
-  dq_entry_t *ret = queue->tail;
+  FAR dq_entry_t *ret = queue->tail;
 
   if (ret)
     {
-      dq_entry_t *prev = ret->blink;
+      FAR dq_entry_t *prev = ret->blink;
       if (!prev)
         {
           queue->head = NULL;
@@ -79,3 +79,4 @@ dq_entry_t *dq_remlast(dq_queue_t *queue)
 
   return ret;
 }
+
diff --git a/lib/lib_fclose.c b/lib/lib_fclose.c
index c1cddeb6911b531915c651c707ea6bdab104dbda..9985c49c249500f933dde09406adac69009e3bf9 100644
--- a/lib/lib_fclose.c
+++ b/lib/lib_fclose.c
@@ -65,7 +65,7 @@ int fclose(FILE *stream)
           ret = close(stream->fs_filedes);
         }
 #warning REVIEW for race conditions
-#if CONFIG_NFILE_STREAMS > 0
+#if CONFIG_STDIO_BUFFER_SIZE > 0
       /* Destroy the semaphore */
       sem_destroy(&stream->fs_sem);
 
diff --git a/lib/lib_fflush.c b/lib/lib_fflush.c
index b3dbb1109648df3ad5b0e4679df83ea12fbe68dc..dc2c99673cf2e86c894d75984aff69bcbf142a35 100644
--- a/lib/lib_fflush.c
+++ b/lib/lib_fflush.c
@@ -88,7 +88,7 @@
 
 /* Called by the OS when a task exits */
 
-void lib_flushall(struct streamlist *list)
+void lib_flushall(FAR struct streamlist *list)
 {
   /* Make sure that there are streams associated with this thread */
   if (list)
diff --git a/lib/lib_filesem.c b/lib/lib_filesem.c
index eb2279b9d1ace402c294bf1c2eb632110d0ee2d6..62b45b4bc445c17a393e3bb5030add4ce664b28d 100644
--- a/lib/lib_filesem.c
+++ b/lib/lib_filesem.c
@@ -39,14 +39,14 @@
 
 #include <nuttx/config.h>
 
-#if CONFIG_STDIO_BUFFER_SIZE > 0
-
 #include <unistd.h>
 #include <semaphore.h>
 #include <errno.h>
 #include <assert.h>
 #include "lib_internal.h"
 
+#if CONFIG_STDIO_BUFFER_SIZE > 0
+
 /************************************************************
  * Definitions
  ************************************************************/
@@ -63,7 +63,7 @@
  * lib_sem_initialize
  ************************************************************/
 
-void lib_sem_initialize(struct file_struct *stream)
+void lib_sem_initialize(FAR struct file_struct *stream)
 {
   /* Initialize the LIB semaphore to one (to support one-at-
    * a-time access to private data sets.
@@ -79,7 +79,7 @@ void lib_sem_initialize(struct file_struct *stream)
  * lib_take_semaphore
  ************************************************************/
 
-void lib_take_semaphore(struct file_struct *stream)
+void lib_take_semaphore(FAR struct file_struct *stream)
 {
   pid_t my_pid = getpid();
 
@@ -115,7 +115,7 @@ void lib_take_semaphore(struct file_struct *stream)
  * lib_give_semaphore
  ************************************************************/
 
-void lib_give_semaphore(struct file_struct *stream)
+void lib_give_semaphore(FAR struct file_struct *stream)
 {
   pid_t my_pid = getpid();
 
diff --git a/lib/lib_fopen.c b/lib/lib_fopen.c
index 0a935ddd23a343030ec034927c23675c80c47eb9..11bce38a27679c4fc559aa8faa653efb5b7424e1 100644
--- a/lib/lib_fopen.c
+++ b/lib/lib_fopen.c
@@ -130,14 +130,14 @@ static int lib_mode2oflags(const char *mode)
  * Public Functions
  ************************************************************/
 
-struct file_struct *lib_fdopen(int fd, const char *mode,
-                                struct filelist *flist,
-                                struct streamlist *slist)
+FAR struct file_struct *lib_fdopen(int fd, const char *mode,
+                                   FAR struct filelist *flist,
+                                   FAR struct streamlist *slist)
 {
-  struct inode      *inode = flist->fl_files[fd].f_inode;
-  FILE               *stream;
-  int                 oflags = lib_mode2oflags(mode);
-  int                 i;
+  FAR struct inode *inode = flist->fl_files[fd].f_inode;
+  FILE             *stream;
+  int               oflags = lib_mode2oflags(mode);
+  int               i;
 
   if (fd < 0 || !flist || !slist)
     {
@@ -209,19 +209,19 @@ struct file_struct *lib_fdopen(int fd, const char *mode,
 
 FILE *fdopen(int fd, const char *mode)
 {
-  struct filelist   *flist  = sched_getfiles();
-  struct streamlist *slist  = sched_getstreams();
+  FAR struct filelist   *flist = sched_getfiles();
+  FAR struct streamlist *slist = sched_getstreams();
   return lib_fdopen(fd, mode, flist, slist);
 }
 
 FILE *fopen(const char *path, const char *mode)
 {
-  struct filelist   *flist  = sched_getfiles();
-  struct streamlist *slist  = sched_getstreams();
-  int                 oflags = lib_mode2oflags(mode);
-  int                 fd     = open(path, oflags, 0666);
+  FAR struct filelist   *flist = sched_getfiles();
+  FAR struct streamlist *slist = sched_getstreams();
+  int oflags = lib_mode2oflags(mode);
+  int fd     = open(path, oflags, 0666);
 
-  FILE *ret   = lib_fdopen(fd, mode, flist, slist);
+  FILE *ret = lib_fdopen(fd, mode, flist, slist);
   if (!ret)
     {
       (void)close(fd);
diff --git a/lib/lib_getenv.c b/lib/lib_getenv.c
index 2c75a4f1623831de110415f9a4263d43bd0ce9bb..dd659393aac8e71dc36816030ee821cee9d48d66 100644
--- a/lib/lib_getenv.c
+++ b/lib/lib_getenv.c
@@ -103,61 +103,68 @@ char *getenv(const char *name)
   const char *pend = &environment[size-1];
   const char *ptmp;
 
-  dbg("getenv(ge): name=\"%s\"\n", name);
-
-  if (name) {
-
-    /* Process each string in the environment. */
-    while (penv < pend) {
-
-      vdbg("(ge):\tCompare to=\"%s\"\n", penv);
-
-      /* The logic below basically implements a version of
-       * strcmp where the strings may be terminated with = signs. */
-      ptmp = name;
-      for (;;) {
-
-	/* Are we at the end of the name-to-matching?  */
-	if ((!*ptmp) || (*ptmp == '=')) {
-
-	  /* Yes.. are we also at the end of the matching-name? */
-	  if (*penv == '=') {
-
-	    /* Yes.. return the pointer to the value. */
-	    dbg("(ge):\tReturning \"%s\"\n", penv+1);
-	    return ((char*)penv+1);
-
-	  } /* end if */
-	  else {
-
-	    /* No.. Skip to the next name matching name candidate. */
-	    while(*penv++);
-	    break;
-	    
-	  } /* end else */
-	} /* end if */
-
-	/* NO.. are we at the end of the matching name candidate? */
-	/* OR.. do the corresponding characters not match. */
-	else if (*penv != *ptmp) {
-
-	  /* Yes.. Skip to the next name matching name candidate. */
-	  while(*penv++);
-	  break;
-	    
-	} /* end else if */
-	else {
-
-	  /* No.. try the next characters. */
-	  penv++; ptmp++;
-
-	} /* end else */
-      } /* end for */
-    } /* end while */
-  } /* end if */
+  dbg("name=\"%s\"\n", name);
+
+  if (name)
+    {
+      /* Process each string in the environment. */
+
+      while (penv < pend)
+        {
+          vdbg("Compare to=\"%s\"\n", penv);
+
+          /* The logic below basically implements a version of
+           * strcmp where the strings may be terminated with = signs.
+           */
+
+          ptmp = name;
+          for (;;)
+            {
+              /* Are we at the end of the name-to-matching?  */
+
+              if (!*ptmp || *ptmp == '=')
+                {
+                  /* Yes.. are we also at the end of the matching-name? */
+
+                  if (*penv == '=')
+                    {
+                      /* Yes.. return the pointer to the value. */
+
+                      dbg("Returning \"%s\"\n", penv+1);
+                      return ((char*)penv+1);
+                    }
+                  else
+                    {
+                      /* No.. Skip to the next name matching name candidate. */
+
+                      while(*penv++);
+                      break;
+                    }
+                }
+
+              /* NO.. are we at the end of the matching name candidate?
+               * OR.. do the corresponding characters not match.
+               */
+
+              else if (*penv != *ptmp)
+                {
+                  /* Yes.. Skip to the next name matching name candidate. */
+
+                  while(*penv++);
+                  break;
+                }
+              else
+                {
+                  /* No.. try the next characters. */
+
+                  penv++; ptmp++;
+                }
+            }
+        }
+    }
 
   /* If we got here, then no matching string was found. */
-		dbg("(ge):\tReturning NULL\n");
-  return NULL;
 
-} /* end getenv */
+  dbg("Returning NULL\n");
+  return NULL;
+}
diff --git a/lib/lib_init.c b/lib/lib_init.c
index a8195937fa969cdb828302f08db3b807f7e82638..d1672de062baaa80bd357ba347d9e8fe0af696b2 100644
--- a/lib/lib_init.c
+++ b/lib/lib_init.c
@@ -57,7 +57,7 @@
  * Private Functions
  ************************************************************/
 
-static void _lib_semtake(struct streamlist *list)
+static void _lib_semtake(FAR struct streamlist *list)
 {
   /* Take the semaphore (perhaps waiting) */
 
@@ -92,10 +92,10 @@ void weak_const_function lib_initialize(void)
  * creates the streamlist instance that is stored in the TCB.
  */
 
-struct streamlist *lib_alloclist(void)
+FAR struct streamlist *lib_alloclist(void)
 {
-  struct streamlist *list;
-  list = (struct streamlist*)kzmalloc(sizeof(struct streamlist));
+  FAR struct streamlist *list;
+  list = (FAR struct streamlist*)kzmalloc(sizeof(struct streamlist));
   if (list)
     {
       int i;
@@ -136,7 +136,7 @@ struct streamlist *lib_alloclist(void)
  * list.
  */
 
-void lib_addreflist(struct streamlist *list)
+void lib_addreflist(FAR struct streamlist *list)
 {
   if (list)
     {
@@ -153,7 +153,7 @@ void lib_addreflist(struct streamlist *list)
  * separately when the file descriptor list is freed.
  */
 
-void lib_releaselist(struct streamlist *list)
+void lib_releaselist(FAR struct streamlist *list)
 {
   int crefs;
   if (list)
@@ -178,7 +178,7 @@ void lib_releaselist(struct streamlist *list)
             sched_free(list);
 
             /* Initialize each FILE structure */
-
+#if CONFIG_STDIO_BUFFER_SIZE > 0
             for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
              {
                /* Destroy the semaphore that protects the IO buffer */
@@ -191,6 +191,7 @@ void lib_releaselist(struct streamlist *list)
                    free(list->sl_streams[i].fs_bufstart);
                  }
              }
+#endif
          }
      }
 }
diff --git a/lib/lib_internal.h b/lib/lib_internal.h
index 736aec54f61d04cb03030ef7cee7c6c7786b651b..9d23e8bf071f05881d8038ad16308725b964d5fc 100644
--- a/lib/lib_internal.h
+++ b/lib/lib_internal.h
@@ -104,8 +104,8 @@ struct lib_rawstream_s
 
 /* Defined in lib_streamsem.c */
 
-extern void  stream_semtake(struct streamlist *list);
-extern void  stream_semgive(struct streamlist *list);
+extern void  stream_semtake(FAR struct streamlist *list);
+extern void  stream_semgive(FAR struct streamlist *list);
 
 /* Defined in lib_memstream.c */
 
@@ -135,8 +135,8 @@ extern int lib_sprintf (struct lib_stream_s *obj,
 
 /* Defined lib_libvsprintf.c */
 
-extern int  lib_vsprintf(struct lib_stream_s *obj,
-                         const char *src, va_list ap);
+extern int lib_vsprintf(struct lib_stream_s *obj,
+                        const char *src, va_list ap);
 
 /* Defined in lib_libwrite.c */
 
@@ -149,9 +149,9 @@ extern ssize_t lib_fread(void *ptr, size_t count, FILE *stream);
 /* Defined in lib_sem.c */
 
 #if CONFIG_STDIO_BUFFER_SIZE > 0
-extern void lib_sem_initialize(struct file_struct *stream);
-extern void lib_take_semaphore(struct file_struct *stream);
-extern void lib_give_semaphore(struct file_struct *stream);
+extern void lib_sem_initialize(FAR struct file_struct *stream);
+extern void lib_take_semaphore(FAR struct file_struct *stream);
+extern void lib_give_semaphore(FAR struct file_struct *stream);
 #endif
 
 /* Defined in lib_libgetbase.c */
diff --git a/lib/lib_libvsprintf.c b/lib/lib_libvsprintf.c
index 2e60ffa22f102ad6e529684ee9431ba7c11c8917..443d17d46db2897950ca7db6a75bada758614d3f 100644
--- a/lib/lib_libvsprintf.c
+++ b/lib/lib_libvsprintf.c
@@ -41,6 +41,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/lib/lib_sscanf.c b/lib/lib_sscanf.c
index efd4ebcfaac73dd172db4d62ca22f51c3057bbe2..13d8c3c0da302bb42570875faf372515acb772ff 100644
--- a/lib/lib_sscanf.c
+++ b/lib/lib_sscanf.c
@@ -37,6 +37,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -128,203 +129,214 @@ int vsscanf(char *buf, const char *s, va_list ap)
       /* Skip over white space */
 
       while (isspace(*s))
-	s++;
+        s++;
 
       /* Check for a conversion specifier */
 
       if (*s == '%')
-	{
-	  vdbg("vsscanf: Specifier found\n");
-
-	  /* Check for qualifiers on the conversion specifier */
-	  s++;
-	  for (; *s; s++)
-	    {
-	      vdbg("vsscanf: Processing %c\n", *s);
-
-	      if (strchr("dibouxcsefg%", *s))
-		break;
-	      if (*s == '*')
-		noassign = 1;
-	      else if (*s == 'l' || *s == 'L')
-		lflag = 1;
-	      else if (*s >= '1' && *s <= '9') {
-		for (tc = s; isdigit(*s); s++);
-		strncpy(tmp, tc, s - tc);
-		tmp[s - tc] = '\0';
-		width = atoi(tmp);
-		/* atob(&width, tmp, 10); */
-		s--;
-	      }
-	    }
-
-	  /* Process %s:  String conversion */
-
-	  if (*s == 's')
-	    {
-	      vdbg("vsscanf: Performing string conversion\n");
-
-	      while (isspace(*buf))
-		buf++;
-	      if (!width)
-		{
-		  width = strcspn(buf, spaces);
-		}
-	      if (!noassign)
-		{
-		  tv = va_arg(ap, char*);
-		  strncpy(tv, buf, width);
-		  tv[width] = '\0';
-		}
-	      buf += width;
-	    }
-
-	  /* Process %c:  Character conversion */
-
-	  else if (*s == 'c')
-	    {
-	      vdbg("vsscanf: Performing character conversion\n");
-
-	      if (!width)
-		width = 1;
-	      if (!noassign)
-		{
-		  tv = va_arg(ap, char*);
-		  strncpy(tv, buf, width);
-		  tv[width] = '\0';
-		}
-	      buf += width;
-	    }
-
-	  /* Process %d, %o, %b, %x, %u:  Various integer conversions */
-
-	  else if (strchr("dobxu", *s))
-	    {
-	      vdbg("vsscanf: Performing integer conversion\n");
-
-	      /* Skip over any white space before the integer string */
-
-	      while (isspace(*buf))
-		buf++;
-
-	      /* The base of the integer conversion depends on the specific
-	       * conversion specification.
-	       */
-
-	      if (*s == 'd' || *s == 'u')
-		base = 10;
-	      else if (*s == 'x')
-		base = 16;
-	      else if (*s == 'o')
-		base = 8;
-	      else if (*s == 'b')
-		base = 2;
-
-	      /* Copy the integer string into a temporary working buffer. */
-
-	      if (!width)
-		{
-		  if (isspace(*(s + 1)) || *(s + 1) == 0)
-		    {
-		      width = strcspn(buf, spaces);
-		    }
-		  else
-		    {
-		      width = strchr(buf, *(s + 1)) - buf;
-		    }
-		}
-	      strncpy(tmp, buf, width);
-	      tmp[width] = '\0';
-
-	      vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
-
-	      /* Perform the integer conversion */
-
-	      buf += width;
-	      if (!noassign)
-		{
-		  int *pint = va_arg(ap, int*);
-		  int tmpint = strtol(tmp, NULL, base);
-		  vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint);
-		  *pint = tmpint;
-		}
-	    }
-
-	  /* Process %f:  Floating point conversion */
-
-	  else if (*s == 'f')
-	    {
-	      vdbg("vsscanf: Performing floating point conversion\n");
-
-	      /* Skip over any white space before the real string */
-
-	      while (isspace(*buf))
-		buf++;
-
-	      /* Copy the real string into a temporary working buffer. */
-
-	      if (!width)
-		{
-		  if (isspace(*(s + 1)) || *(s + 1) == 0)
-		    {
-		      width = strcspn(buf, spaces);
-		    }
-		  else
-		    {
-		      width = strchr(buf, *(s + 1)) - buf;
-		    }
-		}
-	      strncpy(tmp, buf, width);
-	      tmp[width] = '\0';
-	      buf += width;
-
-	      vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
-
-	      /* Perform the floating point conversion */
-
-	      if (!noassign)
-		{
-		  /* strtod always returns a double */
-
-		  double_t dvalue = strtod(tmp, NULL);
-		  void *pv = va_arg(ap, void*);
-
-		  vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv);
-
-		  /* But we have to check whether we need to return a
-		   * float or a double.
-		   */
+        {
+          vdbg("vsscanf: Specifier found\n");
+
+          /* Check for qualifiers on the conversion specifier */
+          s++;
+          for (; *s; s++)
+            {
+              vdbg("vsscanf: Processing %c\n", *s);
+
+              if (strchr("dibouxcsefg%", *s))
+                break;
+              if (*s == '*')
+                noassign = 1;
+              else if (*s == 'l' || *s == 'L')
+                lflag = 1;
+              else if (*s >= '1' && *s <= '9') {
+                for (tc = s; isdigit(*s); s++);
+                strncpy(tmp, tc, s - tc);
+                tmp[s - tc] = '\0';
+                width = atoi(tmp);
+                /* atob(&width, tmp, 10); */
+                s--;
+              }
+            }
+
+          /* Process %s:  String conversion */
+
+          if (*s == 's')
+            {
+              vdbg("vsscanf: Performing string conversion\n");
+
+              while (isspace(*buf))
+                buf++;
+              if (!width)
+                {
+                  width = strcspn(buf, spaces);
+                }
+              if (!noassign)
+                {
+                  tv = va_arg(ap, char*);
+                  strncpy(tv, buf, width);
+                  tv[width] = '\0';
+                }
+              buf += width;
+            }
+
+          /* Process %c:  Character conversion */
+
+          else if (*s == 'c')
+            {
+              vdbg("vsscanf: Performing character conversion\n");
+
+              if (!width)
+                width = 1;
+              if (!noassign)
+                {
+                  tv = va_arg(ap, char*);
+                  strncpy(tv, buf, width);
+                  tv[width] = '\0';
+                }
+              buf += width;
+            }
+
+          /* Process %d, %o, %b, %x, %u:  Various integer conversions */
+
+          else if (strchr("dobxu", *s))
+            {
+              vdbg("vsscanf: Performing integer conversion\n");
+
+              /* Skip over any white space before the integer string */
+
+              while (isspace(*buf))
+                buf++;
+
+              /* The base of the integer conversion depends on the specific
+               * conversion specification.
+               */
+
+              if (*s == 'd' || *s == 'u')
+                base = 10;
+              else if (*s == 'x')
+                base = 16;
+              else if (*s == 'o')
+                base = 8;
+              else if (*s == 'b')
+                base = 2;
+
+              /* Copy the integer string into a temporary working buffer. */
+
+              if (!width)
+                {
+                  if (isspace(*(s + 1)) || *(s + 1) == 0)
+                    {
+                      width = strcspn(buf, spaces);
+                    }
+                  else
+                    {
+                      width = strchr(buf, *(s + 1)) - buf;
+                    }
+                }
+              strncpy(tmp, buf, width);
+              tmp[width] = '\0';
+
+              vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
+
+              /* Perform the integer conversion */
+
+              buf += width;
+              if (!noassign)
+                {
+                  int *pint = va_arg(ap, int*);
+#ifdef SDCC
+                  char *endptr;
+                  int tmpint = strtol(tmp, &endptr, base);
+#else
+                  int tmpint = strtol(tmp, NULL, base);
+#endif
+                  vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint);
+                  *pint = tmpint;
+                }
+            }
+
+          /* Process %f:  Floating point conversion */
+
+          else if (*s == 'f')
+            {
+              vdbg("vsscanf: Performing floating point conversion\n");
+
+              /* Skip over any white space before the real string */
+
+              while (isspace(*buf))
+                {
+                  buf++;
+                }
+
+              /* Copy the real string into a temporary working buffer. */
+
+              if (!width)
+                {
+                  if (isspace(*(s + 1)) || *(s + 1) == 0)
+                    {
+                      width = strcspn(buf, spaces);
+                    }
+                  else
+                    {
+                      width = strchr(buf, *(s + 1)) - buf;
+                    }
+                }
+              strncpy(tmp, buf, width);
+              tmp[width] = '\0';
+              buf += width;
+
+              vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
+
+              /* Perform the floating point conversion */
+
+              if (!noassign)
+                {
+                  /* strtod always returns a double */
+#ifdef SDCC
+                  char *endptr;
+                  double_t dvalue = strtod(tmp,&endptr);
+#else
+                  double_t dvalue = strtod(tmp, NULL);
+#endif
+                  void *pv = va_arg(ap, void*);
+
+                  vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv);
+
+                  /* But we have to check whether we need to return a
+                   * float or a double.
+                   */
 
 #ifdef CONFIG_HAVE_DOUBLE
-		  if (lflag)
-		    {
-		      *((double_t*)pv) = dvalue;
-		    }
-		  else
+                  if (lflag)
+                    {
+                      *((double_t*)pv) = dvalue;
+                    }
+                  else
 #endif
-		    {
-		      *((float*)pv) = (float)dvalue;
-		    }
-		}
-	    }
-
-	  if (!noassign)
-	    count++;
-	  width = noassign = lflag = 0;
-	  s++;
-	}
+                    {
+                      *((float*)pv) = (float)dvalue;
+                    }
+                }
+            }
+
+          if (!noassign)
+            count++;
+          width = noassign = lflag = 0;
+          s++;
+        }
 
     /* Its is not a conversion specifier */
 
       else
-	{
-	  while (isspace(*buf))
-	    buf++;
-	  if (*s != *buf)
-	    break;
-	  else
-	    s++, buf++;
-	}
+        {
+          while (isspace(*buf))
+            buf++;
+          if (*s != *buf)
+            break;
+          else
+            s++, buf++;
+        }
     }
   return count;
 }
diff --git a/lib/lib_strdup.c b/lib/lib_strdup.c
index 285d76c2c6243ed0ad69e147df81face431a49a5..4b3ff8aa5e4b3f6fbbdde9a56412beae9599cf98 100644
--- a/lib/lib_strdup.c
+++ b/lib/lib_strdup.c
@@ -46,12 +46,12 @@
  * Global Functions
  ************************************************************/
 
-char *strdup(const char *s)
+FAR char *strdup(const char *s)
 {
-  char *news = NULL;
+  FAR char *news = NULL;
   if (s)
     {
-      news = malloc(strlen(s) + 1);
+      news = (FAR char*)malloc(strlen(s) + 1);
       if (news)
         {
           strcpy(news, s);
diff --git a/lib/lib_streamsem.c b/lib/lib_streamsem.c
index d0dbad56dc1ff38b313f3ddbdfa4937380999aa5..51536676626a6de574bce2b41a41651002217f58 100644
--- a/lib/lib_streamsem.c
+++ b/lib/lib_streamsem.c
@@ -76,7 +76,7 @@
  * Public Functions
  ************************************************************/
 
-void stream_semtake(struct streamlist *list)
+void stream_semtake(FAR struct streamlist *list)
 {
   /* Take the semaphore (perhaps waiting) */
 
@@ -90,7 +90,7 @@ void stream_semtake(struct streamlist *list)
     }
 }
 
-void stream_semgive(struct streamlist *list)
+void stream_semgive(FAR struct streamlist *list)
 {
   sem_post(&list->sl_sem);
 }
diff --git a/lib/sq_addafter.c b/lib/sq_addafter.c
index 896aed5caef69ee861cf36e6fd70a2aec645ccb9..268365a189fff19366bbd99829650a255dda68ef 100644
--- a/lib/sq_addafter.c
+++ b/lib/sq_addafter.c
@@ -56,7 +56,7 @@
  *
  ************************************************************/
 
-void sq_addafter(sq_entry_t *prev, sq_entry_t *node,
+void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
                  sq_queue_t *queue)
 {
   if (!queue->head || prev == queue->tail)
diff --git a/lib/sq_addfirst.c b/lib/sq_addfirst.c
index f59fbc5684f323321daee143b5dafd610f7ec555..d34677241da58f1967ed9f821ca7748865095ae3 100644
--- a/lib/sq_addfirst.c
+++ b/lib/sq_addfirst.c
@@ -56,7 +56,7 @@
  *
  ************************************************************/
 
-void sq_addfirst(sq_entry_t *node, sq_queue_t *queue)
+void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue)
 {
   node->flink = queue->head;
   if (!queue->head)
diff --git a/lib/sq_addlast.c b/lib/sq_addlast.c
index 172808b33c86a641171704422c661e71a741e23d..f3368dcae77f817511a2c771ca2d5017acb49d8c 100644
--- a/lib/sq_addlast.c
+++ b/lib/sq_addlast.c
@@ -55,7 +55,7 @@
  *   the 'queue'
  ************************************************************/
 
-void sq_addlast(sq_entry_t *node, sq_queue_t *queue)
+void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue)
 {
   node->flink = NULL;
   if (!queue->head)
diff --git a/lib/sq_rem.c b/lib/sq_rem.c
index 30a49b9b18df3343bc40a3cf3a0d3f2190df8328..e5d1bbed51c968bcec81764c6423ba417d29eb5e 100644
--- a/lib/sq_rem.c
+++ b/lib/sq_rem.c
@@ -55,7 +55,7 @@
  *
  ************************************************************/
 
-void sq_rem(sq_entry_t *node, sq_queue_t *queue)
+void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue)
 {
   if (queue->head && node)
     {
@@ -69,8 +69,8 @@ void sq_rem(sq_entry_t *node, sq_queue_t *queue)
         }
       else
         {
-          sq_entry_t *prev;
-          for(prev = (sq_entry_t*)queue->head;
+          FAR sq_entry_t *prev;
+          for(prev = (FAR sq_entry_t*)queue->head;
               prev && prev->flink != node;
               prev = prev->flink);
 
diff --git a/lib/sq_remafter.c b/lib/sq_remafter.c
index 353e8ec0a9c0aa6ba303ba2f7ed85f13ea20df40..d876d3a56edfe3f6d0317774cd86acac09b56666 100644
--- a/lib/sq_remafter.c
+++ b/lib/sq_remafter.c
@@ -56,9 +56,9 @@
  *
  ************************************************************/
 
-sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue)
+FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue)
 {
-  sq_entry_t *ret = node->flink;
+  FAR sq_entry_t *ret = node->flink;
   if (queue->head && ret)
     {
       if (queue->tail == ret)
@@ -76,3 +76,4 @@ sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue)
 
   return ret;
 }
+
diff --git a/lib/sq_remfirst.c b/lib/sq_remfirst.c
index dbbd5f378ffdfab5a3efefbb75a768044c6f64ba..3cb00c599a973344c3019fbc540381759201d3f1 100644
--- a/lib/sq_remfirst.c
+++ b/lib/sq_remfirst.c
@@ -56,9 +56,9 @@
  *
  ************************************************************/
 
-sq_entry_t *sq_remfirst(sq_queue_t *queue)
+FAR sq_entry_t *sq_remfirst(sq_queue_t *queue)
 {
-  sq_entry_t *ret = queue->head;
+  FAR sq_entry_t *ret = queue->head;
 
   if (ret)
     {
@@ -73,3 +73,4 @@ sq_entry_t *sq_remfirst(sq_queue_t *queue)
 
   return ret;
 }
+
diff --git a/lib/sq_remlast.c b/lib/sq_remlast.c
index 35e5cda6a76695a0487e6d45cd42e7477943e899..0e34492a3574b83828ff0e6054fc33381061f128 100644
--- a/lib/sq_remlast.c
+++ b/lib/sq_remlast.c
@@ -55,9 +55,9 @@
  *
  ************************************************************/
 
-sq_entry_t *sq_remlast(sq_queue_t *queue)
+FAR sq_entry_t *sq_remlast(sq_queue_t *queue)
 { 
-  sq_entry_t *ret = queue->tail;
+  FAR sq_entry_t *ret = queue->tail;
 
   if (ret)
     {
@@ -68,7 +68,7 @@ sq_entry_t *sq_remlast(sq_queue_t *queue)
         }
       else
         {
-          sq_entry_t *prev;
+          FAR sq_entry_t *prev;
           for(prev = queue->head;
               prev && prev->flink != ret;
               prev = prev->flink);
diff --git a/mm/Makefile b/mm/Makefile
index ce32beea5d40c30dd56d34a07a9d010d32cd14c8..c00a7a2aed522fcfb147a96a0328c5e0ecc7cd88 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -70,7 +70,7 @@ $(BIN):	$(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/mm/mm_addfreechunk.c b/mm/mm_addfreechunk.c
index f59b9f59ef11c99d46ba3831aaa1a394da887fbc..c3b74a07d8db4c487e3fc38ed6659bac67e5ef71 100644
--- a/mm/mm_addfreechunk.c
+++ b/mm/mm_addfreechunk.c
@@ -61,10 +61,10 @@
  *
  ************************************************************/
 
-void mm_addfreechunk(struct mm_freenode_s *node)
+void mm_addfreechunk(FAR struct mm_freenode_s *node)
 {
-  struct mm_freenode_s *next;
-  struct mm_freenode_s *prev;
+  FAR struct mm_freenode_s *next;
+  FAR struct mm_freenode_s *prev;
 
   /* Convert the size to a nodelist index */
 
diff --git a/mm/mm_calloc.c b/mm/mm_calloc.c
index de69b881c11660c82203d72e2888e902d186a545..6c9db3440b89cd543bd6a6b5479e6d2ebd123619 100644
--- a/mm/mm_calloc.c
+++ b/mm/mm_calloc.c
@@ -55,9 +55,9 @@
  *   calloc calculates the size and calls zalloc
  ************************************************************/
 
-void *calloc(size_t n, size_t elem_size)
+FAR void *calloc(size_t n, size_t elem_size)
 {
-  void *ret = NULL;
+  FAR void *ret = NULL;
 
   if (n > 0 && elem_size > 0)
     {
diff --git a/mm/mm_environment.h b/mm/mm_environment.h
index 8d4816bd0221a3909b35521ec538ab6f0c4f9dbf..14476957de748b849d3de2fcc358d141f6f515cb 100644
--- a/mm/mm_environment.h
+++ b/mm/mm_environment.h
@@ -47,6 +47,7 @@
 
 #ifndef MM_TEST
 # include <nuttx/config.h>
+# include <nuttx/compiler.h>
 # include <sys/types.h>
 # include <stdlib.h>
 # include <string.h>
diff --git a/mm/mm_free.c b/mm/mm_free.c
index 7fb2a061eca4cafee6aba660a17027e1702c047a..276a734d08931f7d24a51853418802b10aac6e1b 100644
--- a/mm/mm_free.c
+++ b/mm/mm_free.c
@@ -62,11 +62,11 @@
  *
  ************************************************************/
 
-void free(void *mem)
+void free(FAR void *mem)
 {
-  struct mm_freenode_s *node;
-  struct mm_freenode_s *prev;
-  struct mm_freenode_s *next;
+  FAR struct mm_freenode_s *node;
+  FAR struct mm_freenode_s *prev;
+  FAR struct mm_freenode_s *next;
 
   /* Protect against attempts to free a NULL reference */
 
@@ -83,22 +83,22 @@ void free(void *mem)
 
   /* Map the memory chunk into a free node */
 
-  node = (struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
+  node = (FAR struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
   node->preceding &= ~MM_ALLOC_BIT;
 
   /* Check if the following node is free and, if so, merge it */
 
-  next = (struct mm_freenode_s *)((char*)node + node->size);
+  next = (FAR struct mm_freenode_s *)((char*)node + node->size);
   if ((next->preceding & MM_ALLOC_BIT) == 0)
     {
-      struct mm_allocnode_s *andbeyond;
+      FAR struct mm_allocnode_s *andbeyond;
 
       /* Get the node following the next node (which will
        * become the new next node). We know that we can never
        * index past the tail chunk because it is always allocated.
        */
 
-      andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
+      andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
 
       /* Remove the next node.  There must be a predecessor,
        * but there may not be a successor node.
@@ -115,14 +115,14 @@ void free(void *mem)
 
       node->size          += next->size;
       andbeyond->preceding =  node->size | (andbeyond->preceding & MM_ALLOC_BIT);
-      next                 = (struct mm_freenode_s *)andbeyond;
+      next                 = (FAR struct mm_freenode_s *)andbeyond;
     }
 
   /* Check if the preceding node is also free and, if so, merge
    * it with this node
    */
 
-  prev = (struct mm_freenode_s *)((char*)node - node->preceding);
+  prev = (FAR struct mm_freenode_s *)((char*)node - node->preceding);
   if ((prev->preceding & MM_ALLOC_BIT) == 0)
     {
       /* Remove the node.  There must be a predecessor, but there may
@@ -146,6 +146,5 @@ void free(void *mem)
   /* Add the merged node to the nodelist */
 
   mm_addfreechunk(node);
-
   mm_givesemaphore();
 }
diff --git a/mm/mm_initialize.c b/mm/mm_initialize.c
index 4bf24a70b8fc21b020bb6be76f6f9b7dc47a946b..6d16a567710862eeac64eb370d6b5e8af13ce5d6 100644
--- a/mm/mm_initialize.c
+++ b/mm/mm_initialize.c
@@ -50,19 +50,19 @@
 
 /* This is the size of the heap provided to mm */
 
-size_t  g_heapsize;
+size_t g_heapsize;
 
 /* This is the first and last nodes of the heap */
 
-struct mm_allocnode_s *g_heapstart;
-struct mm_allocnode_s *g_heapend;
+FAR struct mm_allocnode_s *g_heapstart;
+FAR struct mm_allocnode_s *g_heapend;
 
 /* All free nodes are maintained in a doubly linked list.  This
  * array provides some hooks into the list at various points to
  * speed searches for free nodes.
  */
 
-struct mm_freenode_s g_nodelist[MM_NNODES];
+FAR struct mm_freenode_s g_nodelist[MM_NNODES];
 
 /************************************************************
  * Public Functions
@@ -85,9 +85,11 @@ struct mm_freenode_s g_nodelist[MM_NNODES];
  *
  ************************************************************/
 
-void mm_initialize(void *heapstart, size_t heapsize)
+void mm_initialize(FAR void *heapstart, size_t heapsize)
 {
-  struct mm_freenode_s *node;
+  FAR struct mm_freenode_s *node;
+  size_t heapbase;
+  size_t heapend;
   int i;
 
   CHECK_ALLOCNODE_SIZE;
@@ -97,8 +99,8 @@ void mm_initialize(void *heapstart, size_t heapsize)
    * both aligned with the MM_MIN_CHUNK size.
    */
 
-  size_t heapbase = MM_ALIGN_UP((size_t)heapstart);
-  size_t heapend  = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
+  heapbase = MM_ALIGN_UP((size_t)heapstart);
+  heapend  = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
 
   /* Save the size of the heap */
 
@@ -121,15 +123,15 @@ void mm_initialize(void *heapstart, size_t heapsize)
    * all available memory.
    */
 
-  g_heapstart            = (struct mm_allocnode_s *)heapbase;
+  g_heapstart            = (FAR struct mm_allocnode_s *)heapbase;
   g_heapstart->size      = SIZEOF_MM_ALLOCNODE;
   g_heapstart->preceding = MM_ALLOC_BIT;
 
-  node                   = (struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
+  node                   = (FAR struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
   node->size             = g_heapsize - 2*SIZEOF_MM_ALLOCNODE;
   node->preceding        = SIZEOF_MM_ALLOCNODE;
 
-  g_heapend              = (struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
+  g_heapend              = (FAR struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
   g_heapend->size        = SIZEOF_MM_ALLOCNODE;
   g_heapend->preceding   = node->size | MM_ALLOC_BIT;
 
diff --git a/mm/mm_internal.h b/mm/mm_internal.h
index 27c9f1f3b2430ac20a0987d3e5671c773d017302..e1b9f9beb3c5e885876957838b65d87f25b42ce2 100644
--- a/mm/mm_internal.h
+++ b/mm/mm_internal.h
@@ -120,14 +120,14 @@ struct mm_allocnode_s
 
 struct mm_freenode_s
 {
-  size_t size;                 /* Size of this chunk */
-  size_t preceding;            /* Size of the preceding chunk */
-  struct mm_freenode_s *flink; /* Supports a doubly linked list */
-  struct mm_freenode_s *blink;
+  size_t size;                     /* Size of this chunk */
+  size_t preceding;                /* Size of the preceding chunk */
+  FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
+  FAR struct mm_freenode_s *blink;
 };
 
 #ifdef CONFIG_SMALL_MEMORY
-# define SIZEOF_MM_FREENODE    10
+# define SIZEOF_MM_FREENODE     8
 #else
 # define SIZEOF_MM_FREENODE    16
 #endif
@@ -160,15 +160,15 @@ extern size_t  g_heapsize;
 
 /* This is the first and last nodes of the heap */
 
-extern struct mm_allocnode_s *g_heapstart;
-extern struct mm_allocnode_s *g_heapend;
+extern FAR struct mm_allocnode_s *g_heapstart;
+extern FAR struct mm_allocnode_s *g_heapend;
 
 /* All free nodes are maintained in a doubly linked list.  This
  * array provides some hooks into the list at various points to
  * speed searches for free nodes.
  */
 
-extern struct mm_freenode_s g_nodelist[MM_NNODES];
+extern FAR struct mm_freenode_s g_nodelist[MM_NNODES];
 
 /************************************************************
  * Pulblic Function Prototypes
@@ -177,23 +177,28 @@ extern struct mm_freenode_s g_nodelist[MM_NNODES];
 /* Normally defined in malloc.h */
 
 #ifdef MM_TEST
- extern void *mm_malloc(size_t);
- extern void  mm_free(void*);
- extern void *mm_realloc(void*, size_t);
- extern void *mm_memalign(size_t, size_t);
- extern void *mm_zalloc(size_t);
- extern void *mm_calloc(size_t, size_t);
+ extern FAR void *mm_malloc(size_t);
+ extern void      mm_free(void*);
+ extern FAR void *mm_realloc(void*, size_t);
+ extern FAR void *mm_memalign(size_t, size_t);
+ extern FAR void *mm_zalloc(size_t);
+ extern FAR void *mm_calloc(size_t, size_t);
+#ifdef CONFIG_CAN_PASS_STRUCTS
  extern struct mallinfo mallinfo(void);
+#else
+ extern int       mallinfo(struct mallinfo *info);
+#endif
 #endif
 
-extern void   mm_shrinkchunk(struct mm_allocnode_s *node, size_t size);
-extern void   mm_addfreechunk(struct mm_freenode_s *node);
-extern int    mm_size2ndx(size_t size);
-extern void   mm_seminitialize(void);
-extern void   mm_takesemaphore(void);
-extern void   mm_givesemaphore(void);
+extern void       mm_shrinkchunk(FAR struct mm_allocnode_s *node,
+                                 size_t size);
+extern void       mm_addfreechunk(FAR struct mm_freenode_s *node);
+extern int        mm_size2ndx(size_t size);
+extern void       mm_seminitialize(void);
+extern void       mm_takesemaphore(void);
+extern void       mm_givesemaphore(void);
 #ifdef MM_TEST
- extern int   mm_getsemaphore(void);
+ extern int       mm_getsemaphore(void);
 #endif
 
 #endif /* __MM_INTERNAL_H */
diff --git a/mm/mm_mallinfo.c b/mm/mm_mallinfo.c
index 4aba9770c9a54a942657235d87f53c27ac657322..68c2a7bb77699e3ab1558babcd50ee303ca1bb9f 100644
--- a/mm/mm_mallinfo.c
+++ b/mm/mm_mallinfo.c
@@ -65,15 +65,26 @@
  *
  ************************************************************/
 
+#ifdef CONFIG_CAN_PASS_STRUCTS
 struct mallinfo mallinfo(void)
+#else
+int mallinfo(struct mallinfo *info)
+#endif
 {
-  static struct mallinfo stats;
   struct mm_allocnode_s *node;
   size_t mxordblk = 0; 
   int    ordblks  = 0;  /* Number of non-inuse chunks */
   size_t uordblks = 0;  /* Total allocated space */
   size_t fordblks = 0;  /* Total non-inuse space */
 
+#ifdef CONFIG_CAN_PASS_STRUCTS
+  static struct mallinfo info;
+#else
+  if (!info)
+    {
+      return ERROR;
+    }
+#endif
   /* Visit each node in physical memory */
 
   for (node = g_heapstart;
@@ -99,10 +110,19 @@ struct mallinfo mallinfo(void)
   uordblks += SIZEOF_MM_ALLOCNODE; /* account for the tail node */
   DEBUGASSERT(uordblks + fordblks == g_heapsize);
 
-  stats.arena    = g_heapsize;
-  stats.ordblks  = ordblks;
-  stats.mxordblk = mxordblk;
-  stats.uordblks = uordblks;
-  stats.fordblks = fordblks;
-  return stats;
+#ifdef CONFIG_CAN_PASS_STRUCTS
+  info.arena    = g_heapsize;
+  info.ordblks  = ordblks;
+  info.mxordblk = mxordblk;
+  info.uordblks = uordblks;
+  info.fordblks = fordblks;
+  return info;
+#else
+  info->arena    = g_heapsize;
+  info->ordblks  = ordblks;
+  info->mxordblk = mxordblk;
+  info->uordblks = uordblks;
+  info->fordblks = fordblks;
+  return OK;
+#endif
 }
diff --git a/mm/mm_malloc.c b/mm/mm_malloc.c
index 80a89222b19a603667b71bd6df07b5db7556faaa..05c0f73c860bb9674226f9b8ab80423b81426c30 100644
--- a/mm/mm_malloc.c
+++ b/mm/mm_malloc.c
@@ -85,9 +85,9 @@
  *
  ************************************************************/
 
-void *malloc(size_t size)
+FAR void *malloc(size_t size)
 {
-  struct mm_freenode_s *node;
+  FAR struct mm_freenode_s *node;
   void *ret = NULL;
   int ndx;
 
@@ -142,8 +142,8 @@ void *malloc(size_t size)
 
   if (node)
     {
-      struct mm_freenode_s *remainder;
-      struct mm_freenode_s *next;
+      FAR struct mm_freenode_s *remainder;
+      FAR struct mm_freenode_s *next;
       size_t remaining;
 
       /* Remove the node.  There must be a predecessor, but there may
@@ -169,11 +169,11 @@ void *malloc(size_t size)
         {
           /* Get a pointer to the next node in physical memory */
 
-          next = (struct mm_freenode_s*)(((char*)node) + node->size);
+          next = (FAR struct mm_freenode_s*)(((char*)node) + node->size);
 
           /* Create the remainder node */
 
-          remainder = (struct mm_freenode_s*)(((char*)node) + size);
+          remainder = (FAR struct mm_freenode_s*)(((char*)node) + size);
           remainder->size = remaining;
           remainder->preceding = size;
 
diff --git a/mm/mm_memalign.c b/mm/mm_memalign.c
index 1f5c0772773e0bfa0249931627aa9f7820d70470..7ac192d9c0e88827405a0b78a0eb59909a42ccff 100644
--- a/mm/mm_memalign.c
+++ b/mm/mm_memalign.c
@@ -63,9 +63,9 @@
  *
  ************************************************************/
 
-void *memalign(size_t alignment, size_t size)
+FAR void *memalign(size_t alignment, size_t size)
 {
-  struct mm_allocnode_s *node;
+  FAR struct mm_allocnode_s *node;
   size_t rawchunk;
   size_t alignedchunk;
   size_t mask = (size_t)(alignment - 1);
@@ -115,7 +115,7 @@ void *memalign(size_t alignment, size_t size)
    * node after the allocation.
    */
 
-  node = (struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
+  node = (FAR struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
 
   /* Find the aligned subregion */
 
@@ -125,13 +125,13 @@ void *memalign(size_t alignment, size_t size)
 
   if (alignedchunk != rawchunk)
     {
-      struct mm_allocnode_s *newnode;
-      struct mm_allocnode_s *next;
+      FAR struct mm_allocnode_s *newnode;
+      FAR struct mm_allocnode_s *next;
       size_t precedingsize;
 
       /* Get the node the next node after the allocation. */
 
-      next = (struct mm_allocnode_s*)((char*)node + node->size);
+      next = (FAR struct mm_allocnode_s*)((char*)node + node->size);
 
       /* Make sure that there is space to convert the preceding mm_allocnode_s
        * into an mm_freenode_s.  I think that this should always be true
@@ -139,7 +139,7 @@ void *memalign(size_t alignment, size_t size)
 
       DEBUGASSERT(alignedchunk >= rawchunk + 8);
 
-      newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
+      newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
 
       /* Preceding size is full size of the new 'node,' including
        * SIZEOF_MM_ALLOCNODE
@@ -158,7 +158,7 @@ void *memalign(size_t alignment, size_t size)
       if (precedingsize < SIZEOF_MM_FREENODE)
         {
           alignedchunk += alignment;
-          newnode       = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
+          newnode       = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
           precedingsize = (size_t)newnode - (size_t)node;
         }
 
@@ -184,7 +184,7 @@ void *memalign(size_t alignment, size_t size)
 
       /* Add the original, newly freed node to the free nodelist */
 
-      mm_addfreechunk((struct mm_freenode_s *)node);
+      mm_addfreechunk((FAR struct mm_freenode_s *)node);
 
       /* Replace the original node with the newlay realloaced,
        * aligned node
@@ -206,5 +206,5 @@ void *memalign(size_t alignment, size_t size)
     }
 
   mm_givesemaphore();
-  return (void*)alignedchunk;
+  return (FAR void*)alignedchunk;
 }
diff --git a/mm/mm_realloc.c b/mm/mm_realloc.c
index b288e880a3fe6ef2e3dadc5ec8dbf98475e0d513..52dd56bb7d8f9e557cc23751f3ba604b2f2b5fe1 100644
--- a/mm/mm_realloc.c
+++ b/mm/mm_realloc.c
@@ -73,11 +73,11 @@
  *
  ************************************************************/
 
-void *realloc(void *oldmem, size_t size)
+FAR void *realloc(FAR void *oldmem, size_t size)
 {
-  struct mm_allocnode_s *oldnode;
-  struct mm_freenode_s  *prev;
-  struct mm_freenode_s  *next;
+  FAR struct mm_allocnode_s *oldnode;
+  FAR struct mm_freenode_s  *prev;
+  FAR struct mm_freenode_s  *next;
   size_t oldsize;
   size_t prevsize = 0;
   size_t nextsize = 0;
@@ -106,7 +106,7 @@ void *realloc(void *oldmem, size_t size)
 
   /* Map the memory chunk into an allocated node structure */
 
-  oldnode = (struct mm_allocnode_s *)((char*)oldmem - SIZEOF_MM_ALLOCNODE);
+  oldnode = (FAR struct mm_allocnode_s *)((FAR char*)oldmem - SIZEOF_MM_ALLOCNODE);
 
   /* We need to hold the MM semaphore while we muck with the
    * nodelist.
@@ -129,13 +129,13 @@ void *realloc(void *oldmem, size_t size)
    * the best decision
    */
 
-  next = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
+  next = (FAR struct mm_freenode_s *)((FAR char*)oldnode + oldnode->size);
   if ((next->preceding & MM_ALLOC_BIT) == 0)
     {
       nextsize = next->size;
     }
 
-  prev = (struct mm_freenode_s *)((char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
+  prev = (FAR struct mm_freenode_s *)((FAR char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
   if ((prev->preceding & MM_ALLOC_BIT) == 0)
     {
       prevsize = prev->size;
@@ -145,9 +145,9 @@ void *realloc(void *oldmem, size_t size)
 
   if (nextsize + prevsize + oldsize >= size)
     {
-      size_t needed = size - oldsize;
-      size_t takeprev;
-      size_t takenext;
+      size_t needed   = size - oldsize;
+      size_t takeprev = 0;
+      size_t takenext = 0;
 
       /* Check if we can extend into the previous chunk and if the
        * previous chunk is smaller than the next chunk.
@@ -207,7 +207,7 @@ void *realloc(void *oldmem, size_t size)
 
       if (takeprev)
         {
-           struct mm_allocnode_s *newnode;
+           FAR struct mm_allocnode_s *newnode;
 
            /* Remove the previous node.  There must be a predecessor,
             * but there may not be a successor node.
@@ -222,7 +222,7 @@ void *realloc(void *oldmem, size_t size)
 
            /* Extend the node into the previous free chunk */
 
-           newnode = (struct mm_allocnode_s *)((char*)oldnode - takeprev);
+           newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev);
 
            /* Did we consume the entire preceding chunk? */
 
@@ -261,12 +261,12 @@ void *realloc(void *oldmem, size_t size)
 
       if (takenext)
         {
-           struct mm_freenode_s *newnode;
-           struct mm_allocnode_s *andbeyond;
+           FAR struct mm_freenode_s *newnode;
+           FAR struct mm_allocnode_s *andbeyond;
 
            /* Get the chunk following the next node (which could be the tail chunk) */
 
-           andbeyond = (struct mm_allocnode_s*)((char*)next + nextsize);
+           andbeyond = (FAR struct mm_allocnode_s*)((char*)next + nextsize);
 
            /* Remove the next node.  There must be a predecessor,
             * but there may not be a successor node.
@@ -282,7 +282,7 @@ void *realloc(void *oldmem, size_t size)
            /* Extend the node into the previous next chunk */
 
            oldnode->size = oldsize + takenext;
-           newnode       = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
+           newnode       = (FAR struct mm_freenode_s *)((char*)oldnode + oldnode->size);
 
            /* Did we consume the entire preceding chunk? */
 
@@ -310,19 +310,21 @@ void *realloc(void *oldmem, size_t size)
 
 
       mm_givesemaphore();
-      return (void*)((char*)oldnode + SIZEOF_MM_ALLOCNODE);
+      return (FAR void*)((FAR char*)oldnode + SIZEOF_MM_ALLOCNODE);
     }
 
   /* The current chunk cannot be extended.  Just allocate a new chunk and copy */
 
   else
     {
+       FAR void *newmem;
+
        /* Allocate a new block.  On failure, realloc must return NULL but
         * leave the original memory in place.
         */
 
        mm_givesemaphore();
-       char *newmem = (char*)malloc(size);
+       newmem = (FAR void*)malloc(size);
        if (newmem)
          {
            memcpy(newmem, oldmem, oldsize);
diff --git a/mm/mm_shrinkchunk.c b/mm/mm_shrinkchunk.c
index 8869f045c7b58291078c40c451417c1a97f94771..4612c426d07e0712ff3be3c648d4e3087a3acb76 100644
--- a/mm/mm_shrinkchunk.c
+++ b/mm/mm_shrinkchunk.c
@@ -64,24 +64,24 @@
  *
  ************************************************************/
 
-void  mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
+void  mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
 {
-  struct mm_freenode_s *next;
+  FAR struct mm_freenode_s *next;
 
   /* Get a reference to the next node */
 
-  next = (struct mm_freenode_s*)((char*)node + node->size);
+  next = (FAR struct mm_freenode_s*)((char*)node + node->size);
 
   /* Check if it is free */
 
   if ((next->preceding & MM_ALLOC_BIT) == 0)
     {
-      struct mm_allocnode_s *andbeyond;
-      struct mm_freenode_s *newnode;
+      FAR struct mm_allocnode_s *andbeyond;
+      FAR struct mm_freenode_s *newnode;
 
       /* Get the chunk next the next node (which could be the tail chunk) */
 
-      andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
+      andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
 
       /* Remove the next node.  There must be a predecessor, but there may
        * not be a successor node.
@@ -98,7 +98,7 @@ void  mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
        * and the tailing memory from the aligned chunk.
        */
 
-      newnode = (struct mm_freenode_s*)((char*)node + size);
+      newnode = (FAR struct mm_freenode_s*)((char*)node + size);
 
       /* Set up the size of the new node */
 
@@ -118,13 +118,13 @@ void  mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
 
   else if (node->size >= size + SIZEOF_MM_FREENODE)
     {
-      struct mm_freenode_s *newnode;
+      FAR struct mm_freenode_s *newnode;
 
       /* Create a new chunk that will hold both the next chunk
        * and the tailing memory from the aligned chunk.
        */
 
-      newnode = (struct mm_freenode_s*)((char*)node + size);
+      newnode = (FAR struct mm_freenode_s*)((char*)node + size);
 
       /* Set up the size of the new node */
 
diff --git a/mm/mm_zalloc.c b/mm/mm_zalloc.c
index a26992b001a9246bf689ba7d208ad6d29a654c0a..270839cac70be650110b148406156e0fef4ab772 100644
--- a/mm/mm_zalloc.c
+++ b/mm/mm_zalloc.c
@@ -56,9 +56,9 @@
  *
  ************************************************************/
 
-void *zalloc(size_t size)
+FAR void *zalloc(size_t size)
 {
-  void *alloc = malloc(size);
+  FAR void *alloc = malloc(size);
   if (alloc)
     {
        memset(alloc, 0, size);
diff --git a/sched/Makefile b/sched/Makefile
index 5efa4a6f02b742ecd61c5eb3ad7de48bda12a971..e5dc3881dced92c89fcf97473e9243bc69a88e4d 100644
--- a/sched/Makefile
+++ b/sched/Makefile
@@ -40,7 +40,7 @@ MKDEP		= $(TOPDIR)/tools/mkdeps.sh
 ASRCS		= 
 AOBJS		= $(ASRCS:.S=.o)
 
-MISC_SRCS	= os_start.c get_errno_ptr.c get_errorptr.c \
+MISC_SRCS	= os_start.c get_errno_ptr.c \
 		  sched_setupstreams.c sched_getfiles.c sched_getstreams.c \
 		  sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \
 		  sched_releasefiles.c
@@ -124,7 +124,7 @@ $(BIN): $(OBJS)
 depend: .depend
 
 clean:
-	rm -f $(BIN) *.o *.asm *.lst *.sym *~
+	rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
 
 distclean: clean
 	rm -f Make.dep .depend
diff --git a/sched/get_errno_ptr.c b/sched/get_errno_ptr.c
index c9f0d52c84cd3e394e02ab75b87dd603f8624c1a..7a8084c71a105d008dbb03e1d82d578b8e063054 100644
--- a/sched/get_errno_ptr.c
+++ b/sched/get_errno_ptr.c
@@ -61,9 +61,9 @@
  *
  ************************************************************/
 
-int *get_errno_ptr(void)
+FAR int *get_errno_ptr(void)
 {
-  _TCB *ptcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head;
   return &ptcb->errno;
 }
 
diff --git a/sched/get_errorptr.c b/sched/get_errorptr.c
deleted file mode 100644
index 7cfad6cb13212e67d7ecf0b70fabc58e75e6ec74..0000000000000000000000000000000000000000
--- a/sched/get_errorptr.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/************************************************************
- * get_errorptr.c
- *
- *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
- *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
- *    used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ************************************************************/
-
-/************************************************************
- * Included Files
- ************************************************************/
-
-#include <sys/types.h>
-#include <errno.h>
-
-/************************************************************
- * Global Functions
- ************************************************************/
-
-/************************************************************
- * Function:  get_errorptr
- *
- * Description:
- *   Return a pointer that is just ERROR cast to void *.
- *   most fully performing processors don't need anything
- *   like this.  Hoever, this little of nonsense is necessary
- *   for some processors where sizeof(pointer) < sizeof(uint32)
- *   and which do not support casts of integers to pointers.
- *
- * Parameters:
- *   None
- *
- * Return Value:
- *   ERROR cast as a pointer value
- *
- * Assumptions:
- *
- ************************************************************/
-
-void *get_errnorptr(void)
-{
-#ifdef CONFIG_CAN_CAST_POINTERS
-  return (void*)ERROR;
-#else
-  union
-  {
-    void  *verror;
-    sint32 ierror;
-  } u;
-
-  u.ierror = ERROR;
-  return u.verror;
-#endif
-}
-
-
diff --git a/sched/irq_attach.c b/sched/irq_attach.c
index d67a04a49728cdf75788512556fa33b4d9335bbe..3032bf1b6cb29fb8665f3318e82a252b1d82feb3 100644
--- a/sched/irq_attach.c
+++ b/sched/irq_attach.c
@@ -76,6 +76,7 @@
 
 int irq_attach(int irq, xcpt_t isr)
 {
+#if NR_IRQS > 0
   int ret = ERROR;
 
   if ((unsigned)irq < NR_IRQS)
@@ -102,6 +103,9 @@ int irq_attach(int irq, xcpt_t isr)
     }
 
   return ret;
+#else
+  return OK;
+#endif
 }
 
 
diff --git a/sched/irq_dispatch.c b/sched/irq_dispatch.c
index d6466cbc0d9016de7d907f3a39c1fed106daccee..1dc388a400e3a6243edaa36bd9e92e7309d633db 100644
--- a/sched/irq_dispatch.c
+++ b/sched/irq_dispatch.c
@@ -76,12 +76,13 @@
  *
  ***********************************************************/
 
-void irq_dispatch(int irq, void *context)
+void irq_dispatch(int irq, FAR void *context)
 {
   xcpt_t vector;
 
   /* Perform some sanity checks */
 
+#if NR_IRQS > 0
   if ((unsigned)irq >= NR_IRQS || g_irqvector[irq] == NULL)
     {
       vector = irq_unexpected_isr;
@@ -90,6 +91,9 @@ void irq_dispatch(int irq, void *context)
     {
       vector = g_irqvector[irq];
     }
+#else
+  vector = irq_unexpected_isr;
+#endif
 
   /* Then dispatch to the interrupt handler */
 
diff --git a/sched/irq_internal.h b/sched/irq_internal.h
index 211779bc370f0e14fca61c9918ebbc73edb74dfe..a1216fa9d2ff4fbb9f9e10534caf1ea4489681a9 100644
--- a/sched/irq_internal.h
+++ b/sched/irq_internal.h
@@ -71,7 +71,7 @@ extern "C" {
 #endif
 
 EXTERN void weak_function irq_initialize(void);
-EXTERN int irq_unexpected_isr(int irq, void *context);
+EXTERN int irq_unexpected_isr(int irq, FAR void *context);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/sched/irq_unexpectedisr.c b/sched/irq_unexpectedisr.c
index 6ca3e1da83125f648a1858df6dcb6545081f3a9a..b7b6b4ae2b4433887da1290372f833e995e5c2c6 100644
--- a/sched/irq_unexpectedisr.c
+++ b/sched/irq_unexpectedisr.c
@@ -75,7 +75,7 @@
  *
  ************************************************************/
 
-int irq_unexpected_isr(int irq, void *context)
+int irq_unexpected_isr(int irq, FAR void *context)
 {
   (void)irqsave();
    PANIC(OSERR_UNEXPECTEDISR);
diff --git a/sched/mq_close.c b/sched/mq_close.c
index 88fe0e043836ac5be2d36a8d38157cea5d0e047a..6643cc5e9afede048ea154728d3ecc12f325668b 100644
--- a/sched/mq_close.c
+++ b/sched/mq_close.c
@@ -75,7 +75,7 @@
  *
  ************************************************************/
 
-#define mq_desfree(mqdes) sq_addlast((sq_entry_t*)mqdes, &g_desfree)
+#define mq_desfree(mqdes) sq_addlast((FAR sq_entry_t*)mqdes, &g_desfree)
 
 /************************************************************
  * Public Functions
@@ -113,10 +113,10 @@
 
 int mq_close(mqd_t mqdes)
 {
-  _TCB      *rtcb = (_TCB*)g_readytorun.head;
-  msgq_t    *msgq;
-  irqstate_t saved_state;
-  int        ret = ERROR;
+  FAR _TCB    *rtcb = (FAR _TCB*)g_readytorun.head;
+  FAR msgq_t *msgq;
+  irqstate_t  saved_state;
+  int         ret = ERROR;
 
   /* Verify the inputs */
 
@@ -128,7 +128,7 @@ int mq_close(mqd_t mqdes)
         * list of message descriptors.
         */
 
-       sq_rem((sq_entry_t*)mqdes, &rtcb->msgdesq);
+       sq_rem((FAR sq_entry_t*)mqdes, &rtcb->msgdesq);
 
        /* Find the message queue associated with the message descriptor */
 
@@ -165,7 +165,7 @@ int mq_close(mqd_t mqdes)
             */
 
            saved_state = irqsave();
-           (void)sq_rem((sq_entry_t*)msgq, &g_msgqueues);
+           (void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
            irqrestore(saved_state);
 
            /* Then deallocate it (and any messages left in it) */
@@ -183,3 +183,4 @@ int mq_close(mqd_t mqdes)
 
    return ret;
 }
+
diff --git a/sched/mq_descreate.c b/sched/mq_descreate.c
index f631cfd2bf8095d89e61a6cf97a98c9e032ed062..98026ad192fdd5ac91bf51b6ecb9518e8e153154 100644
--- a/sched/mq_descreate.c
+++ b/sched/mq_descreate.c
@@ -132,7 +132,7 @@ static mqd_t mq_desalloc(void)
  *
  ************************************************************/
 
-mqd_t mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags)
+mqd_t mq_descreate(FAR _TCB* mtcb, FAR msgq_t* msgq, int oflags)
 {
   mqd_t mqdes;
 
@@ -149,7 +149,7 @@ mqd_t mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags)
 
       /* And add it to the specified tasks's TCB */
 
-      sq_addlast((sq_entry_t*)mqdes, &mtcb->msgdesq);
+      sq_addlast((FAR sq_entry_t*)mqdes, &mtcb->msgdesq);
     }
 
   return mqdes;
diff --git a/sched/mq_findnamed.c b/sched/mq_findnamed.c
index f01e24d1f30973d5b4cec5f76bdb2c4f2da279f3..a74caba7b950ba60938d67479c0026546382a156 100644
--- a/sched/mq_findnamed.c
+++ b/sched/mq_findnamed.c
@@ -81,13 +81,13 @@
  *
  ************************************************************/
 
-msgq_t *mq_findnamed(const char *mq_name)
+FAR msgq_t *mq_findnamed(const char *mq_name)
 {
-  msgq_t *msgq;
+  FAR msgq_t *msgq;
 
   /* Search the list of named message queues */
 
-  for (msgq = (msgq_t*)g_msgqueues.head; (msgq); msgq = msgq->flink)
+  for (msgq = (FAR msgq_t*)g_msgqueues.head; (msgq); msgq = msgq->flink)
     {
       /* Break out of the lloop with a non-NULL msgq if the
        * name matches.
diff --git a/sched/mq_initialize.c b/sched/mq_initialize.c
index deff6a2545bbbe736a7ae356a5a9a39c20a5c9f0..df8e981e631859e803630ef7e7bdc1940aeff0ef 100644
--- a/sched/mq_initialize.c
+++ b/sched/mq_initialize.c
@@ -144,7 +144,7 @@ static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16 nmsgs,
       for (i = 0; i < nmsgs; i++)
         {
           mqmsg->type = alloc_type;
-          sq_addlast((sq_entry_t*)mqmsg++, queue);
+          sq_addlast((FAR sq_entry_t*)mqmsg++, queue);
         }
     }
 
@@ -233,13 +233,13 @@ void mq_desblockalloc(void)
        * we ever need to reclaim the memory.
        */
 
-      sq_addlast(&mqdesblock->queue, &g_desalloc);
+      sq_addlast((FAR sq_entry_t*)&mqdesblock->queue, &g_desalloc);
 
       /* Then add each message queue descriptor to the free list */
 
       for (i = 0; i < NUM_MSG_DESCRIPTORS; i++)
         {
-          sq_addlast((sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree);
+          sq_addlast((FAR sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree);
         }
     }
 }
diff --git a/sched/mq_internal.h b/sched/mq_internal.h
index ba2368e43fd504ecf1fe11318cc5c8baf47a7dc2..4e55a931611fead0d9d64428b26f56c7c36838e6 100644
--- a/sched/mq_internal.h
+++ b/sched/mq_internal.h
@@ -95,13 +95,12 @@ struct mqmsg
    * MQ_type.
    */
 
-  struct mqmsg  *next;        /* Forward link to next message */
-  ubyte          type;        /* (Used to manage allocations) */
+  FAR struct mqmsg  *next;    /* Forward link to next message */
+  ubyte        type;          /* (Used to manage allocations) */
 
-  ubyte          priority;    /* priority of message          */
-  ubyte          msglen;      /* Message data length          */
-  ubyte          pad;         /* Not used                     */
-  uint16         mail[MQ_MAX_HWORDS]; /* Message data         */
+  ubyte        priority;      /* priority of message          */
+  ubyte        msglen;        /* Message data length          */
+  uint16       mail[MQ_MAX_HWORDS]; /* Message data           */
 };
 typedef struct mqmsg mqmsg_t;
 
@@ -111,20 +110,20 @@ struct mq_des; /* forward reference */
 
 struct msgq_s
 {
-  struct msgq_s *flink;         /* Forward link to next message queue */
-  sq_queue_t     msglist;       /* Prioritized message list */
-  sint16         maxmsgs;       /* Maximum number of messages in the queue */
-  sint16         nmsgs;         /* Number of message in the queue */
-  sint16         nconnect;      /* Number of connections to message queue */
-  sint16         nwaitnotfull;  /* Number tasks waiting for not full */
-  sint16         nwaitnotempty; /* Number tasks waiting for not empty */
-  ubyte          maxmsgsize;    /* Max size of message in message queue */
-  boolean        unlinked;      /* TRUE if the msg queue has been unlinked */
-  struct mq_des *ntmqdes;       /* Notification: Owning mqdes (NULL if none) */
-  pid_t          ntpid;         /* Notification: Receiving Task's PID */
-  int            ntsigno;       /* Notification: Signal number */
-  union sigval   ntvalue;       /* Notification: Signal value */
-  char           name[1];       /* Start of the queue name */
+  FAR struct msgq_s *flink;   /* Forward link to next message queue */
+  sq_queue_t   msglist;       /* Prioritized message list */
+  sint16       maxmsgs;       /* Maximum number of messages in the queue */
+  sint16       nmsgs;         /* Number of message in the queue */
+  sint16       nconnect;      /* Number of connections to message queue */
+  sint16       nwaitnotfull;  /* Number tasks waiting for not full */
+  sint16       nwaitnotempty; /* Number tasks waiting for not empty */
+  ubyte        maxmsgsize;    /* Max size of message in message queue */
+  boolean      unlinked;      /* TRUE if the msg queue has been unlinked */
+  FAR struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */
+  pid_t        ntpid;         /* Notification: Receiving Task's PID */
+  int          ntsigno;       /* Notification: Signal number */
+  union sigval ntvalue;       /* Notification: Signal value */
+  char         name[1];       /* Start of the queue name */
 };
 
 #define SIZEOF_MQ_HEADER ((int)(((msgq_t*)NULL)->name))
@@ -135,9 +134,9 @@ struct msgq_s
 
 struct mq_des
 {
-  struct mq_des *flink;       /* Forward link to next message descriptor */
-  msgq_t        *msgq;        /* Pointer to associated message queue */
-  int            oflags;      /* Flags set when message queue was opened */
+  FAR struct mq_des *flink;   /* Forward link to next message descriptor */
+  FAR msgq_t  *msgq;          /* Pointer to associated message queue */
+  int          oflags;        /* Flags set when message queue was opened */
 };
 
 /************************************************************
@@ -182,12 +181,12 @@ extern "C" {
 /* Functions defined in mq_initialized.c *******************/
 
 EXTERN void weak_function mq_initialize(void);
-EXTERN void    mq_desblockalloc(void);
+EXTERN void        mq_desblockalloc(void);
 
-EXTERN mqd_t   mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags);
-EXTERN msgq_t *mq_findnamed(const char *mq_name);
-EXTERN void    mq_msgfree(mqmsg_t *mqmsg);
-EXTERN void    mq_msgqfree(msgq_t *msgq);
+EXTERN mqd_t       mq_descreate(FAR _TCB* mtcb, FAR msgq_t* msgq, int oflags);
+EXTERN FAR msgq_t *mq_findnamed(const char *mq_name);
+EXTERN void        mq_msgfree(FAR mqmsg_t *mqmsg);
+EXTERN void        mq_msgqfree(FAR msgq_t *msgq);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/sched/mq_msgfree.c b/sched/mq_msgfree.c
index f9246d8fcfd5c7555cca509a817db60cdcd42bd4..f7a236f15311de9f8eb18ed1f14de738f9a7827f 100644
--- a/sched/mq_msgfree.c
+++ b/sched/mq_msgfree.c
@@ -84,7 +84,7 @@
  *
  ************************************************************/
 
-void mq_msgfree(mqmsg_t * mqmsg)
+void mq_msgfree(FAR mqmsg_t *mqmsg)
 {
   irqstate_t saved_state;
 
@@ -99,7 +99,7 @@ void mq_msgfree(mqmsg_t * mqmsg)
        */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)mqmsg, &g_msgfree);
+      sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfree);
       irqrestore(saved_state);
     }
 
@@ -114,7 +114,7 @@ void mq_msgfree(mqmsg_t * mqmsg)
        */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)mqmsg, &g_msgfreeirq);
+      sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfreeirq);
       irqrestore(saved_state);
     }
 
diff --git a/sched/mq_msgqfree.c b/sched/mq_msgqfree.c
index 59a27603e1c99bdd4dc4d482ee78e2e217123acd..06d5da81582425181933a78444eb215b5d78acfc 100644
--- a/sched/mq_msgqfree.c
+++ b/sched/mq_msgqfree.c
@@ -84,14 +84,14 @@
  *
  ************************************************************/
 
-void mq_msgqfree(msgq_t *msgq)
+void mq_msgqfree(FAR msgq_t *msgq)
 {
-  mqmsg_t  *curr;
-  mqmsg_t  *next;
+  FAR mqmsg_t *curr;
+  FAR mqmsg_t *next;
 
   /* Deallocate any stranded messages in the message queue. */
 
-  curr = (mqmsg_t*)msgq->msglist.head;
+  curr = (FAR mqmsg_t*)msgq->msglist.head;
   while (curr)
     {
       /* Deallocate the message structure. */
diff --git a/sched/mq_open.c b/sched/mq_open.c
index d4ad2a322f58cb0ff387782cf6c7931c432d1f93..e3e239180ae5a5729d36f61772edc89ac17ee0b0 100644
--- a/sched/mq_open.c
+++ b/sched/mq_open.c
@@ -103,8 +103,8 @@
 
 mqd_t mq_open(const char *mq_name, int oflags, ...)
 {
-  _TCB           *rtcb = (_TCB*)g_readytorun.head;
-  msgq_t         *msgq;
+  FAR _TCB       *rtcb = (FAR _TCB*)g_readytorun.head;
+  FAR msgq_t     *msgq;
   mqd_t           mqdes = NULL;
   va_list         arg;          /* Points to each un-named argument */
   mode_t          mode;         /* MQ creation mode parameter (ignored) */
@@ -151,7 +151,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
                * of the message queue name+1.
                */
 
-              msgq = (msgq_t*)kzmalloc(SIZEOF_MQ_HEADER + namelen + 1);
+              msgq = (FAR msgq_t*)kzmalloc(SIZEOF_MQ_HEADER + namelen + 1);
               if (msgq)
                 {
                   /* Create a message queue descriptor for the TCB */
@@ -196,7 +196,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
                        * message queues
                        */
 
-                      sq_addlast((sq_entry_t*)msgq, &g_msgqueues);
+                      sq_addlast((FAR sq_entry_t*)msgq, &g_msgqueues);
 
                       /* Clean-up variable argument stuff */
 
@@ -218,11 +218,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
 
   if (mqdes == NULL)
     {
-#ifdef CONFIG_CAN_CAST_POINTERS
       return (mqd_t)ERROR;
-#else
-      return get_errorptr();
-#endif
     }
   else
     {
diff --git a/sched/mq_receive.c b/sched/mq_receive.c
index 4e7555e13b0f572cf95e3596484ac11bc4356390..649dfae7a2a65c8e136c29006b4650380e8b7a58 100644
--- a/sched/mq_receive.c
+++ b/sched/mq_receive.c
@@ -114,13 +114,13 @@
 
 int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
 {
-  _TCB      *rtcb;
-  _TCB      *btcb;
-  msgq_t    *msgq;
-  mqmsg_t   *curr;
-  irqstate_t saved_state;
-  ubyte      rcvmsglen;
-  int        ret = ERROR;
+  FAR _TCB    *rtcb;
+  FAR _TCB    *btcb;
+  FAR msgq_t  *msgq;
+  FAR mqmsg_t *curr;
+  irqstate_t   saved_state;
+  ubyte        rcvmsglen;
+  int          ret = ERROR;
 
   /* Verify the input parameters */
 
@@ -142,7 +142,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
 
       /* Get the message from the head of the queue */
 
-      while ((curr = (mqmsg_t*)sq_remfirst(&msgq->msglist)) == NULL)
+      while ((curr = (FAR mqmsg_t*)sq_remfirst(&msgq->msglist)) == NULL)
         {
           /* Should we block until there the above condition has been
            * satisfied?
@@ -152,7 +152,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
             {
               /* Block and try again */
 
-              rtcb = (_TCB*)g_readytorun.head;
+              rtcb = (FAR _TCB*)g_readytorun.head;
               rtcb->msgwaitq = msgq;
               msgq->nwaitnotempty++;
               up_block_task(rtcb, TSTATE_WAIT_MQNOTEMPTY);
@@ -207,7 +207,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
                */
 
               saved_state = irqsave();
-              for (btcb = (_TCB*)g_waitingformqnotfull.head;
+              for (btcb = (FAR _TCB*)g_waitingformqnotfull.head;
                    btcb && btcb->msgwaitq != msgq;
                    btcb = btcb->flink);
 
diff --git a/sched/mq_send.c b/sched/mq_send.c
index 0a9a125151a623fb8d0ae0665bff9cae087918b5..aaf700a45124d91232570e77226ce2e8ec6ee92c 100644
--- a/sched/mq_send.c
+++ b/sched/mq_send.c
@@ -37,6 +37,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <nuttx/kmalloc.h>
 #include <sys/types.h>      /* uint32, etc. */
 #include <mqueue.h>
@@ -92,10 +93,10 @@
  *
  ************************************************************/
 
-mqmsg_t *mq_msgalloc(void)
+FAR mqmsg_t *mq_msgalloc(void)
 {
-  mqmsg_t   *mqmsg;
-  irqstate_t saved_state;
+  FAR mqmsg_t *mqmsg;
+  irqstate_t   saved_state;
 
   /* If we were called from an interrupt handler, then try to
    * get the message from generally available list of messages.
@@ -107,12 +108,12 @@ mqmsg_t *mq_msgalloc(void)
     {
       /* Try the general free list */
 
-      mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfree);
+      mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
       if (!mqmsg)
         {
           /* Try the free list reserved for interrupt handlers */
 
-          mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfreeirq);
+          mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfreeirq);
         }
     }
 
@@ -125,14 +126,14 @@ mqmsg_t *mq_msgalloc(void)
        */
 
       saved_state = irqsave();
-      mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfree);
+      mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
       irqrestore(saved_state);
 
       /* If we cannot a message from the free list, then we will have to allocate one. */
 
       if (!mqmsg)
         {
-          mqmsg = (mqmsg_t *)kmalloc((sizeof (mqmsg_t)));
+          mqmsg = (FAR mqmsg_t *)kmalloc((sizeof (mqmsg_t)));
 
           /* Check if we got an allocated message */
 
@@ -152,7 +153,6 @@ mqmsg_t *mq_msgalloc(void)
     }
 
   return(mqmsg);
-
 }
 
 /************************************************************
@@ -202,14 +202,14 @@ mqmsg_t *mq_msgalloc(void)
 
 int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
 {
-  _TCB      *rtcb;
-  _TCB      *btcb;
-  msgq_t    *msgq;
-  mqmsg_t   *curr;
-  mqmsg_t   *next;
-  mqmsg_t   *prev;
-  irqstate_t saved_state;
-  int        ret = ERROR;
+  FAR _TCB    *rtcb;
+  FAR _TCB    *btcb;
+  FAR msgq_t  *msgq;
+  FAR mqmsg_t *curr;
+  FAR mqmsg_t *next;
+  FAR mqmsg_t *prev;
+  irqstate_t   saved_state;
+  int          ret = ERROR;
 
   /* Verify the input parameters */
 
@@ -267,7 +267,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
                    * When we are unblocked, we will try again
                    */
 
-                  rtcb = (_TCB*)g_readytorun.head;
+                  rtcb = (FAR _TCB*)g_readytorun.head;
                   rtcb->msgwaitq = msgq;
                   (msgq->nwaitnotfull)++;
                   up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
@@ -314,7 +314,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
            * message. Each is list is maintained in ascending priority order.
            */
 
-          for (prev = NULL, next = (mqmsg_t*)msgq->msglist.head;
+          for (prev = NULL, next = (FAR mqmsg_t*)msgq->msglist.head;
                next && prio <= next->priority;
                prev = next, next = next->next);
 
@@ -322,12 +322,12 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
 
           if (prev)
             {
-              sq_addafter((sq_entry_t*)prev, (sq_entry_t*)curr,
+              sq_addafter((FAR sq_entry_t*)prev, (FAR sq_entry_t*)curr,
                           &msgq->msglist);
             }
           else
             {
-              sq_addfirst((sq_entry_t*)curr, &msgq->msglist);
+              sq_addfirst((FAR sq_entry_t*)curr, &msgq->msglist);
             }
 
           /* Increment the count of message in the queue */
@@ -378,7 +378,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
                * interrupts should never cause a change in this list
                */
 
-              for (btcb = (_TCB*)g_waitingformqnotempty.head;
+              for (btcb = (FAR _TCB*)g_waitingformqnotempty.head;
                    btcb && btcb->msgwaitq != msgq;
                    btcb = btcb->flink);
 
diff --git a/sched/mq_unlink.c b/sched/mq_unlink.c
index 066bcacabb18202c4aff88868b0af1e3cb9f12a3..17b5767ae34a7eb8a169549933f729152389476d 100644
--- a/sched/mq_unlink.c
+++ b/sched/mq_unlink.c
@@ -89,9 +89,9 @@
 
 int mq_unlink(const char *mq_name)
 {
-  msgq_t    *msgq;
-  irqstate_t saved_state;
-  int        ret = ERROR;
+  FAR msgq_t *msgq;
+  irqstate_t  saved_state;
+  int         ret = ERROR;
 
   /* Verify the input values */
 
@@ -115,7 +115,7 @@ int mq_unlink(const char *mq_name)
                */
 
               saved_state = irqsave();
-              (void)sq_rem((sq_entry_t*)msgq, &g_msgqueues);
+              (void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
               irqrestore(saved_state);
 
               /* Then deallocate it (and any messages left in it) */
@@ -140,3 +140,4 @@ int mq_unlink(const char *mq_name)
 
   return ret;
 }
+
diff --git a/sched/os_internal.h b/sched/os_internal.h
index 4e4cdf7d67a40cc74ed6ed48d7cabba868e69b9e..75807e930a07473027cff476d1da2a0e265dd542 100644
--- a/sched/os_internal.h
+++ b/sched/os_internal.h
@@ -123,8 +123,8 @@ enum os_crash_codes_e
 
 struct pidhash_s
 {
-  _TCB *tcb;
-  pid_t pid;
+  FAR _TCB *tcb;
+  pid_t     pid;
 };
 typedef struct pidhash_s  pidhash_t;
 
@@ -135,8 +135,8 @@ typedef struct pidhash_s  pidhash_t;
 
 struct tasklist_s
 {
-  dq_queue_t *list;        /* Pointer to the task list */
-  boolean     prioritized; /* TRUE if the list is prioritized */
+  NEAR dq_queue_t *list;        /* Pointer to the task list */
+  boolean          prioritized; /* TRUE if the list is prioritized */
 };
 typedef struct tasklist_s tasklist_t;
 
@@ -232,32 +232,32 @@ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES];
  * Public Function Prototypes
  ************************************************************/
 
-extern STATUS  _task_init(_TCB *tcb, char *name, int priority,
+extern STATUS  _task_init(FAR _TCB *tcb, const char *name, int priority,
                           start_t start, main_t main,
                           boolean pthread,
-                          char *arg1, char *arg2,
-                          char *arg3, char *arg4);
+                          FAR char *arg1, FAR char *arg2,
+                          FAR char *arg3, FAR char *arg4);
 
-extern boolean sched_addreadytorun(_TCB *rtrtcb);
-extern boolean sched_removereadytorun(_TCB *rtrtcb);
-extern boolean sched_addprioritized(_TCB *newTcb,
-                                    dq_queue_t *list);
+extern boolean sched_addreadytorun(FAR _TCB *rtrtcb);
+extern boolean sched_removereadytorun(FAR _TCB *rtrtcb);
+extern boolean sched_addprioritized(FAR _TCB *newTcb,
+                                    NEAR dq_queue_t *list);
 extern boolean sched_mergepending(void);
-extern void    sched_addblocked(_TCB *btcb, tstate_t task_state);
-extern void    sched_removeblocked(_TCB *btcb);
-extern _TCB   *sched_gettcb(pid_t pid);
+extern void    sched_addblocked(FAR _TCB *btcb, tstate_t task_state);
+extern void    sched_removeblocked(FAR _TCB *btcb);
+extern FAR _TCB *sched_gettcb(pid_t pid);
 
 #if CONFIG_NFILE_DESCRIPTORS > 0
-extern int     sched_setupidlefiles(_TCB *tcb);
-extern int     sched_setuptaskfiles(_TCB *tcb);
-extern int     sched_setuppthreadfiles(_TCB *tcb);
+extern int     sched_setupidlefiles(FAR _TCB *tcb);
+extern int     sched_setuptaskfiles(FAR _TCB *tcb);
+extern int     sched_setuppthreadfiles(FAR _TCB *tcb);
 #if CONFIG_NFILE_STREAMS > 0
-extern int     sched_setupstreams(_TCB *tcb);
-extern int     sched_flushfiles(_TCB *tcb);
+extern int     sched_setupstreams(FAR _TCB *tcb);
+extern int     sched_flushfiles(FAR _TCB *tcb);
 #endif
-extern int     sched_releasefiles(_TCB *tcb);
+extern int     sched_releasefiles(FAR _TCB *tcb);
 #endif
 
-extern int     sched_releasetcb(_TCB *tcb);
+extern int     sched_releasetcb(FAR _TCB *tcb);
 
 #endif /* __OS_INTERNAL_H */
diff --git a/sched/os_start.c b/sched/os_start.c
index 09de22ce3fa7b6641e40dc26effab2e42821a9fd..249134a987ebe5396b269afa6047c775b4a3958f 100644
--- a/sched/os_start.c
+++ b/sched/os_start.c
@@ -42,6 +42,7 @@
 #include <string.h>
 
 #include <nuttx/arch.h>
+#include <nuttx/compiler.h>
 #include <nuttx/fs.h>
 #include <nuttx/lib.h>
 #include <nuttx/os_external.h>
@@ -170,7 +171,7 @@ const tasklist_t g_tasklisttable[NUM_TASK_STATES] =
  * for bringing up the rest of the system
  */
 
-static _TCB g_idletcb;
+static FAR _TCB g_idletcb;
 
 /************************************************************
  * Private Function Prototypes
@@ -239,7 +240,7 @@ void os_start(void)
 
   /* Then add the idle task's TCB to the head of the ready to run list */
 
-  dq_addfirst((dq_entry_t*)&g_idletcb, &g_readytorun);
+  dq_addfirst((FAR dq_entry_t*)&g_idletcb, &g_readytorun);
 
   /* Initialize the processor-specific portion of the TCB */
 
@@ -249,7 +250,7 @@ void os_start(void)
 
 #ifndef CONFIG_HEAP_BASE
   {
-    void *heap_start;
+    FAR void *heap_start;
     size_t heap_size;
     up_allocate_heap(&heap_start, &heap_size);
     mm_initialize(heap_start, heap_size);
diff --git a/sched/pthread_completejoin.c b/sched/pthread_completejoin.c
index 8e57ada8bab9dbeebf3fb134594ad52d62bcf3f0..571bb6862405e9a761560c1c868fe7d30f2a3d50 100644
--- a/sched/pthread_completejoin.c
+++ b/sched/pthread_completejoin.c
@@ -74,7 +74,7 @@
  *
  ************************************************************/
 
-static void pthread_destroyjoininfo(join_t *pjoin)
+static void pthread_destroyjoininfo(FAR join_t *pjoin)
 {
   int ntasks_waiting;
   int status;
@@ -145,9 +145,9 @@ static void pthread_destroyjoininfo(join_t *pjoin)
  *
  ************************************************************/
 
-int pthread_completejoin(pid_t pid, void *exit_value)
+int pthread_completejoin(pid_t pid, FAR void *exit_value)
 {
-  join_t *pjoin;
+  FAR join_t *pjoin;
   boolean detached = FALSE;
 
   dbg("process_id=%d exit_value=%p\n", pid, exit_value);
@@ -186,7 +186,7 @@ int pthread_completejoin(pid_t pid, void *exit_value)
 
           /* Deallocate the join entry if it was detached. */
 
-          sched_free((void*)pjoin);
+          sched_free((FAR void*)pjoin);
         }
 
      /* No, then we can assume that some other thread is waiting for the join info */
diff --git a/sched/pthread_condtimedwait.c b/sched/pthread_condtimedwait.c
index 9ebaf691786b491a8a4cc1b57589e653ce008f53..43cd1501c96a4d3b0ed606b254cdac51b634dd5b 100644
--- a/sched/pthread_condtimedwait.c
+++ b/sched/pthread_condtimedwait.c
@@ -37,6 +37,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <pthread.h>
@@ -71,6 +72,25 @@
  * Private Functions
  ************************************************************/
 
+/************************************************************
+ * Function:  pthread_condtimedout
+ *
+ * Description:
+ *   This function is called if the timeout elapses before
+ *   the condition is signaled.
+ *
+ * Parameters:
+ *   argc  - the number of arguments (should be 2)
+ *   pid   - the task ID of the task to wateup
+ *   signo - The signal to use to wake up the task
+ *
+ * Return Value:
+ *   None
+ *
+ * Assumptions:
+ *
+ ************************************************************/
+
 static void pthread_condtimedout(int argc, uint32 pid, uint32 signo, ...)
 {
 #ifdef CONFIG_CAN_PASS_STRUCTS
@@ -85,6 +105,70 @@ static void pthread_condtimedout(int argc, uint32 pid, uint32 signo, ...)
 #endif
 }
 
+/************************************************************
+ * Function:  pthread_timeoutticks
+ *
+ * Description:
+ *   Convert a timespec delay to system timer ticks.
+ *
+ * Parameters:
+ *   abstime - wait until this absolute time
+ *
+ * Return Value:
+ *   The relative number of ticks to wait (or ERROR on
+ *   failure;
+ *
+ * Assumptions:
+ *   Interrupts should be disabled so that the time is
+ *   not changing during the calculation
+ *
+ ************************************************************/
+
+int pthread_timeouticks(const struct timespec *abstime, int *ticks)
+{
+  struct timespec currtime;
+  struct timespec reltime;
+  sint32          relusec;
+  int             ret;
+
+  /* Convert the timespec to clock ticks.  NOTE: Here we use
+   * internal knowledge that CLOCK_REALTIME is defined to be zero!
+   */
+
+  ret = clock_gettime(0, &currtime);
+  if (ret)
+    {
+      return EINVAL;
+    }
+
+  /* The relative time to wait is the absolute time minus the
+   * current time.
+   */
+
+  reltime.tv_nsec = (abstime->tv_nsec - currtime.tv_nsec);
+  reltime.tv_sec  = (abstime->tv_sec  - currtime.tv_sec);
+
+  /* Check if we were supposed to borrow from the seconds to
+   * borrow from the seconds
+   */
+
+  if (reltime.tv_nsec < 0)
+    {
+      reltime.tv_nsec += NSEC_PER_SEC;
+      reltime.tv_sec  -= 1;
+    }
+
+  /* Convert this relative time into microseconds.*/
+
+  relusec = reltime.tv_sec * USEC_PER_SEC +
+            reltime.tv_nsec / NSEC_PER_USEC;
+
+  /* Convert microseconds to clock ticks */
+
+  *ticks = relusec / USEC_PER_TICK;
+  return OK;
+}
+
 /************************************************************
  * Public Functions
  ************************************************************/
@@ -96,10 +180,13 @@ static void pthread_condtimedout(int argc, uint32 pid, uint32 signo, ...)
  *   A thread can perform a timed wait on a condition variable.
  *
  * Parameters:
- *   None
+ *   cond   - the condition variable to wait on
+ *   mutex   - the mutex that protects the condition variable
+ *   abstime - wait until this absolute time
  *
  * Return Value:
- *   None
+ *   OK (0) on success; ERROR (-1) on failure with errno
+ *   set appropriately.
  *
  * Assumptions:
  *   Timing is of resolution 1 msec, with +/-1 millisecond
@@ -110,10 +197,7 @@ static void pthread_condtimedout(int argc, uint32 pid, uint32 signo, ...)
 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
                            const struct timespec *abstime)
 {
-  struct timespec currtime;
-  struct timespec reltime;
   WDOG_ID         wdog;
-  sint32          relusec;
   sint32          ticks;
   int             mypid = (int)getpid();
   irqstate_t      int_state;
@@ -169,11 +253,9 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 
           /* Convert the timespec to clock ticks.  We must disable pre-emption
            * here so that this time stays valid until the wait begins.
-           * NOTE:  Here we use internal knowledge that CLOCK_REALTIME is
-           * defined to be zero!
            */
 
-          ret = clock_gettime(0, &currtime);
+          ret = pthread_timeouticks(abstime, &ticks);
           if (ret)
             {
               /* Restore interrupts  (pre-emption will be enabled when
@@ -184,33 +266,6 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
             }
           else
             {
-              /* The relative time to wait is the absolute time minus the
-               * the current time.
-               */
-
-              reltime.tv_nsec = (abstime->tv_nsec - currtime.tv_nsec);
-              reltime.tv_sec  = (abstime->tv_sec  - currtime.tv_sec);
-
-              /* Check if we were supposed to borrow from the seconds
-               * to borrow from the seconds
-               */
-
-              if (reltime.tv_nsec < 0)
-                {
-                  reltime.tv_nsec += NSEC_PER_SEC;
-                  reltime.tv_sec  -= 1;
-                }
-
-              /* Convert this relative time into microseconds.*/
-
-              relusec =
-                reltime.tv_sec * USEC_PER_SEC +
-                reltime.tv_nsec / NSEC_PER_USEC;
-
-              /* Convert microseconds to clock ticks */
-
-              ticks = relusec / USEC_PER_TICK;
-
               /* Check the absolute time to wait.  If it is now or in the past, then
                * just return with the timedout condition.
                */
diff --git a/sched/pthread_create.c b/sched/pthread_create.c
index a369f0b49533a5972e105ff7a52575fdf41474f3..ebf212516a1ec4e99bc5dcabe17c6a98f7096f23 100644
--- a/sched/pthread_create.c
+++ b/sched/pthread_create.c
@@ -63,7 +63,7 @@
 
 /* Default pthread attributes */
 
-pthread_attr_t g_default_pthread_attr =
+FAR pthread_attr_t g_default_pthread_attr =
 {
   PTHREAD_STACK_DEFAULT,    /* stacksize */
   PTHREAD_DEFAULT_PRIORITY, /* priority */
@@ -96,7 +96,7 @@ pthread_attr_t g_default_pthread_attr =
  *
  ************************************************************/
 
-static void pthread_addjoininfo(join_t *pjoin)
+static void pthread_addjoininfo(FAR join_t *pjoin)
 {
   pjoin->next = NULL;
   if (!g_pthread_tail)
@@ -124,8 +124,8 @@ static void pthread_addjoininfo(join_t *pjoin)
 
 static void pthread_start(void)
 {
-  _TCB *ptcb = (_TCB*)g_readytorun.head;
-  join_t *pjoin = (join_t*)ptcb->joininfo;
+  FAR _TCB   *ptcb  = (FAR _TCB*)g_readytorun.head;
+  FAR join_t *pjoin = (FAR join_t*)ptcb->joininfo;
   pthread_addr_t exit_status;
 
   /* Sucessfully spawned, add the pjoin to our data set.
@@ -175,8 +175,8 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
                    pthread_startroutine_t startRoutine,
                    pthread_addr_t arg)
 {
-  _TCB *ptcb;
-  join_t *pjoin;
+  FAR _TCB *ptcb;
+  FAR join_t *pjoin;
   STATUS status;
   int priority;
 #if CONFIG_RR_INTERVAL > 0
@@ -193,7 +193,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
 
   /* Allocate a TCB for the new task. */
 
-  ptcb = (_TCB*)kzmalloc(sizeof(_TCB));
+  ptcb = (FAR _TCB*)kzmalloc(sizeof(_TCB));
   if (!ptcb)
     {
       *get_errno_ptr() = ENOMEM;
@@ -210,7 +210,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
 
   /* Allocate a detachable structure to support pthread_join logic */
 
-  pjoin = (join_t*)kzmalloc(sizeof(join_t));
+  pjoin = (FAR join_t*)kzmalloc(sizeof(join_t));
   if (!pjoin)
     {
       sched_releasetcb(ptcb);
@@ -242,6 +242,10 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
         {
           priority = param.sched_priority;
         }
+      else
+        {
+          priority = SCHED_FIFO;
+        }
 
       /* Get the scheduler policy for this thread */
 
@@ -266,7 +270,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
   /* Initialize the task */
 
   status = _task_init(ptcb, NULL, priority, pthread_start, (main_t)startRoutine,
-                      TRUE, (char*)arg, NULL, NULL, NULL);
+                      TRUE, (FAR char*)arg, NULL, NULL, NULL);
   if (status != OK)
     {
 
@@ -331,7 +335,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
   else
     {
       sched_unlock();
-      dq_rem((dq_entry_t*)ptcb, &g_inactivetasks);
+      dq_rem((FAR dq_entry_t*)ptcb, &g_inactivetasks);
       (void)sem_destroy(&pjoin->data_sem);
       (void)sem_destroy(&pjoin->exit_sem);
       sched_releasetcb(ptcb);
diff --git a/sched/pthread_detach.c b/sched/pthread_detach.c
index 4306b28e44ef5375306848cf25a173f25cda9f03..ca3f732f40cea1893574b55cce04f5b24d09b2f3 100644
--- a/sched/pthread_detach.c
+++ b/sched/pthread_detach.c
@@ -87,7 +87,7 @@
 
 int pthread_detach(pthread_t thread)
 {
-  join_t *pjoin;
+  FAR join_t *pjoin;
   int ret;
 
   dbg("Thread=%d\n", thread);
diff --git a/sched/pthread_exit.c b/sched/pthread_exit.c
index e6ed040d49cba6cad5c30ee75f669c93efa89618..cd0833ba626a1cf5d32639e7caa0eab198a3cdc1 100644
--- a/sched/pthread_exit.c
+++ b/sched/pthread_exit.c
@@ -86,7 +86,7 @@
  *
  ************************************************************/
 
-void pthread_exit(void *exit_value)
+void pthread_exit(FAR void *exit_value)
 {
   int error_code = (int)exit_value;
   int status;
@@ -117,3 +117,4 @@ void pthread_exit(void *exit_value)
 
   _exit(error_code);
 }
+
diff --git a/sched/pthread_findjoininfo.c b/sched/pthread_findjoininfo.c
index 1d33c50e0077d3df19779f69f9dc57afdcb06228..893e0655136d7941cab8af2dad84ca2884d652ba 100644
--- a/sched/pthread_findjoininfo.c
+++ b/sched/pthread_findjoininfo.c
@@ -81,9 +81,9 @@
  *
  ************************************************************/
 
-join_t *pthread_findjoininfo(pid_t pid)
+FAR join_t *pthread_findjoininfo(pid_t pid)
 {
-  join_t *pjoin;
+  FAR join_t *pjoin;
 
   /* Find the entry with the matching pid */
 
diff --git a/sched/pthread_getspecific.c b/sched/pthread_getspecific.c
index afcfba55c2dd0022cc9941f3524b10c118d6540c..c3eec886fde5e8fd923800beb4a0c9de4bf23861 100644
--- a/sched/pthread_getspecific.c
+++ b/sched/pthread_getspecific.c
@@ -103,11 +103,11 @@
  *
  ************************************************************/
 
-void *pthread_getspecific(pthread_key_t key)
+FAR void *pthread_getspecific(pthread_key_t key)
 {
 #if CONFIG_NPTHREAD_KEYS > 0
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
-  void *ret = NULL;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
+  FAR void *ret = NULL;
 
   /* Check if the key is valid. */
 
@@ -123,3 +123,4 @@ void *pthread_getspecific(pthread_key_t key)
   return NULL;
 #endif
 }
+
diff --git a/sched/pthread_initialize.c b/sched/pthread_initialize.c
index e1b24f432f05ef947118ce3752218dc1de4294ca..599d63ebffcd6816db5c4b32ea1f0ecf91411eaf 100644
--- a/sched/pthread_initialize.c
+++ b/sched/pthread_initialize.c
@@ -58,8 +58,8 @@
  * is used to retain information about the spawned threads.
  */
 
-join_t *g_pthread_head = NULL;
-join_t *g_pthread_tail = NULL;
+FAR join_t *g_pthread_head = NULL;
+FAR join_t *g_pthread_tail = NULL;
 
 /* Mutually exclusive access to this data set is enforced with
  * the following (un-named) semaphore.
@@ -191,3 +191,4 @@ int pthread_givesemaphore(sem_t *sem)
       return ERROR;
     }
 }
+
diff --git a/sched/pthread_internal.h b/sched/pthread_internal.h
index f23bafe5cbb9cea3ed0d51c8394bd434e52043b1..34a2f518d1e78f85be509e9d1300cd0270df3513 100644
--- a/sched/pthread_internal.h
+++ b/sched/pthread_internal.h
@@ -63,7 +63,7 @@
 
 struct join_s 
 {
-  struct join_s *next;           /* Implements link list */
+  FAR struct join_s *next;       /* Implements link list */
   boolean        started;        /* TRUE: pthread started. */
   boolean        detached;       /* TRUE: pthread_detached'ed */
   boolean        terminated;     /* TRUE: detach'ed+exit'ed */
@@ -83,8 +83,8 @@ typedef struct join_s join_t;
  * is used to retain information about the spawned threads.
  */
 
-extern join_t *g_pthread_head;
-extern join_t *g_pthread_tail;
+extern FAR join_t *g_pthread_head;
+extern FAR join_t *g_pthread_tail;
 
 /* Mutually exclusive access to this data set is enforced with
  * the following (un-named) semaphore.
@@ -100,7 +100,7 @@ extern ubyte g_pthread_num_keys;
 
 /* Default pthread attributes */
 
-extern pthread_attr_t g_default_pthread_attr;
+extern FAR pthread_attr_t g_default_pthread_attr;
 
 /************************************************************
  * Public Function Prototypes
@@ -114,10 +114,10 @@ extern "C" {
 #endif
 
 EXTERN void weak_function pthread_initialize(void);
-EXTERN int                pthread_completejoin(pid_t pid, void *exit_value);
-EXTERN join_t            *pthread_findjoininfo(pid_t pid);
+EXTERN int                pthread_completejoin(pid_t pid, FAR void *exit_value);
+EXTERN FAR join_t        *pthread_findjoininfo(pid_t pid);
 EXTERN int                pthread_givesemaphore(sem_t *sem);
-EXTERN join_t            *pthread_removejoininfo(pid_t pid);
+EXTERN FAR join_t        *pthread_removejoininfo(pid_t pid);
 EXTERN int                pthread_takesemaphore(sem_t *sem);
 
 #undef EXTERN
diff --git a/sched/pthread_join.c b/sched/pthread_join.c
index 28c8bf1c9d6230b38823d2f79ec8255bbc6539eb..2754a35fe6c95a0285476e338e1d03a9aacf3fa7 100644
--- a/sched/pthread_join.c
+++ b/sched/pthread_join.c
@@ -95,7 +95,7 @@
 
 int pthread_join(pthread_t thread, pthread_addr_t *pexit_value)
 {
-  join_t *pjoin;
+  FAR join_t *pjoin;
   int ret;
 
   dbg("thread=%d\n", thread);
@@ -129,7 +129,7 @@ int pthread_join(pthread_t thread, pthread_addr_t *pexit_value)
     {
       /* Determine what kind of error to return */
 
-      _TCB *tcb = sched_gettcb((pthread_t)thread);
+      FAR _TCB *tcb = sched_gettcb((pthread_t)thread);
 
       dbg("Could not find thread data\n");
 
@@ -211,3 +211,4 @@ int pthread_join(pthread_t thread, pthread_addr_t *pexit_value)
   dbg("Returning %d\n", ret);
   return ret;
 }
+
diff --git a/sched/pthread_removejoininfo.c b/sched/pthread_removejoininfo.c
index 33fb2439189d9889ae78e2346c2f33e5b7c833bb..e989d9ab8d0b302d4f42dfac85a28790ecf78df6 100644
--- a/sched/pthread_removejoininfo.c
+++ b/sched/pthread_removejoininfo.c
@@ -81,10 +81,10 @@
  *
  ************************************************************/
 
-join_t *pthread_removejoininfo(pid_t pid)
+FAR join_t *pthread_removejoininfo(pid_t pid)
 {
-  join_t *prev;
-  join_t *join;
+  FAR join_t *prev;
+  FAR join_t *join;
 
   /* Find the entry with the matching pid */
 
@@ -134,3 +134,4 @@ join_t *pthread_removejoininfo(pid_t pid)
 
   return join;
 }
+
diff --git a/sched/pthread_setspecific.c b/sched/pthread_setspecific.c
index 5e9ba7fb62ff1a8be2f4dc1e58b453c2410f5bb6..4e8414dcfdf3771f96a1cd6382c561d0329b90a8 100644
--- a/sched/pthread_setspecific.c
+++ b/sched/pthread_setspecific.c
@@ -111,10 +111,10 @@
  *
  ************************************************************/
 
-int pthread_setspecific(pthread_key_t key, void *value)
+int pthread_setspecific(pthread_key_t key, FAR void *value)
 {
 #if CONFIG_NPTHREAD_KEYS > 0
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   int ret = EINVAL;
 
   /* Check if the key is valid. */
@@ -136,4 +136,3 @@ int pthread_setspecific(pthread_key_t key, void *value)
 #endif
 }
 
-
diff --git a/sched/sched_addblocked.c b/sched/sched_addblocked.c
index 195937832e99e46eb185765c592399c8ab567295..648d3f5816331be7e095cb7d773f64d1ade5ac57 100644
--- a/sched/sched_addblocked.c
+++ b/sched/sched_addblocked.c
@@ -86,7 +86,7 @@
  *
  ************************************************************/
 
-void sched_addblocked(_TCB *btcb, tstate_t task_state)
+void sched_addblocked(FAR _TCB *btcb, tstate_t task_state)
 {
    /* Make sure that we received a valid blocked state */
 
@@ -108,10 +108,11 @@ void sched_addblocked(_TCB *btcb, tstate_t task_state)
      {
        /* Add the task to a non-prioritized list */
 
-       dq_addlast((dq_entry_t*)btcb, g_tasklisttable[task_state].list);
+       dq_addlast((FAR dq_entry_t*)btcb, g_tasklisttable[task_state].list);
      }
 
    /* Make sure the TCB's state corresponds to the list */
 
    btcb->task_state = task_state;
 }
+
diff --git a/sched/sched_addprioritized.c b/sched/sched_addprioritized.c
index 54e792048405a84b6ff23cd8aa4170d0d4721c96..9b0c89e817fa43553c5ca8f436858534346cc0ae 100644
--- a/sched/sched_addprioritized.c
+++ b/sched/sched_addprioritized.c
@@ -91,10 +91,10 @@
  *   match the state associated with the list.
  ************************************************************/
 
-boolean sched_addprioritized(_TCB *tcb, dq_queue_t *list)
+boolean sched_addprioritized(FAR _TCB *tcb, NEAR dq_queue_t *list)
 {
-  _TCB *next;
-  _TCB *prev;
+  FAR _TCB *next;
+  FAR _TCB *prev;
   ubyte sched_priority = tcb->sched_priority;
   boolean ret = FALSE;
 
@@ -106,7 +106,7 @@ boolean sched_addprioritized(_TCB *tcb, dq_queue_t *list)
    * Each is list is maintained in ascending sched_priority order.
    */
 
-  for (next = (_TCB*)list->head;
+  for (next = (FAR _TCB*)list->head;
       (next && sched_priority <= next->sched_priority);
       next = next->flink);
 
@@ -119,15 +119,15 @@ boolean sched_addprioritized(_TCB *tcb, dq_queue_t *list)
     {
       /* The tcb goes at the end of the list. */
 
-      prev = (_TCB*)list->tail;
+      prev = (FAR _TCB*)list->tail;
       if (!prev)
         {
           /* Special case:  The list is empty */
 
           tcb->flink = NULL;
           tcb->blink = NULL;
-          list->head = (dq_entry_t*)tcb;
-          list->tail = (dq_entry_t*)tcb;
+          list->head = (FAR dq_entry_t*)tcb;
+          list->tail = (FAR dq_entry_t*)tcb;
           ret = TRUE;
         }
       else
@@ -137,22 +137,22 @@ boolean sched_addprioritized(_TCB *tcb, dq_queue_t *list)
           tcb->flink = NULL;
           tcb->blink = prev;
           prev->flink = tcb;
-          list->tail = (dq_entry_t*)tcb;
+          list->tail = (FAR dq_entry_t*)tcb;
         }
     }
   else
     {
       /* The tcb goes just before next */
 
-      prev = (_TCB*)next->blink;
+      prev = (FAR _TCB*)next->blink;
       if (!prev)
         {
           /* Special case:  Insert at the head of the list */
 
-          tcb->flink = next;
-          tcb->blink = NULL;
+          tcb->flink  = next;
+          tcb->blink  = NULL;
           next->blink = tcb;
-          list->head = (dq_entry_t*)tcb;
+          list->head  = (FAR dq_entry_t*)tcb;
           ret = TRUE;
         }
       else
@@ -168,3 +168,4 @@ boolean sched_addprioritized(_TCB *tcb, dq_queue_t *list)
 
   return ret;
 }
+
diff --git a/sched/sched_addreadytorun.c b/sched/sched_addreadytorun.c
index c52da36702c9fff2b718ab626332a7cbaf3b095f..3192fc7f9dda76e8c69c0ae2860e6becf3b26fe7 100644
--- a/sched/sched_addreadytorun.c
+++ b/sched/sched_addreadytorun.c
@@ -94,9 +94,9 @@
  *   the head of the g_readytorun list is changed.
  ************************************************************/
 
-boolean sched_addreadytorun(_TCB *btcb)
+boolean sched_addreadytorun(FAR _TCB *btcb)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   boolean ret;
 
   /* Check if pre-emption is disabled for the current running task and
diff --git a/sched/sched_free.c b/sched/sched_free.c
index dc1d34789481ffb7067edf1b39ce09cd868050e2..96292426e50b56b56395438fff5da20c2c970fb5 100644
--- a/sched/sched_free.c
+++ b/sched/sched_free.c
@@ -80,7 +80,7 @@
  *
  ************************************************************/
 
-void sched_free(void *address)
+void sched_free(FAR void *address)
 {
   /* Check if this is an attempt to deallocate memory from
    * an exception handler.
@@ -91,7 +91,7 @@ void sched_free(void *address)
       /* Yes.. Delay the deallocation until a more appropriate time. */
 
       irqstate_t saved_state = irqsave();
-      sq_addlast((sq_entry_t*)address, &g_delayeddeallocations);
+      sq_addlast((FAR sq_entry_t*)address, &g_delayeddeallocations);
       irqrestore(saved_state);
     }
   else
@@ -101,3 +101,4 @@ void sched_free(void *address)
       kfree(address);
     }
 }
+
diff --git a/sched/sched_getfiles.c b/sched/sched_getfiles.c
index d6986a5bcdb0fea5b136709daa38a4ada09846aa..7478e7cf08f8bfd82902cc0504c90f6aa8b09c09 100644
--- a/sched/sched_getfiles.c
+++ b/sched/sched_getfiles.c
@@ -68,9 +68,9 @@
  *
  ************************************************************/
 
-struct filelist *sched_getfiles(void)
+FAR struct filelist *sched_getfiles(void)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   return rtcb->filelist;
 }
 
diff --git a/sched/sched_getparam.c b/sched/sched_getparam.c
index 85d8c55c77118a15a0b667d04403cac3ae430314..e78c07fc58629b7eb120b450a456c30570a44df3 100644
--- a/sched/sched_getparam.c
+++ b/sched/sched_getparam.c
@@ -96,8 +96,8 @@
 
 int sched_getparam (pid_t pid, struct sched_param * param)
 {
-  _TCB *rtcb;
-  _TCB *tcb;
+  FAR _TCB *rtcb;
+  FAR _TCB *tcb;
   int ret = OK;
 
   if (!param)
@@ -107,7 +107,7 @@ int sched_getparam (pid_t pid, struct sched_param * param)
 
   /* Check if the task to restart is the calling task */
 
-  rtcb = (_TCB*)g_readytorun.head;
+  rtcb = (FAR _TCB*)g_readytorun.head;
   if ((pid == 0) || (pid == rtcb->pid))
     {
        /* Return the priority if the calling task. */
@@ -140,3 +140,4 @@ int sched_getparam (pid_t pid, struct sched_param * param)
 
   return ret;
 }
+
diff --git a/sched/sched_getstreams.c b/sched/sched_getstreams.c
index fef913bc4a4a4b4dc28727da27c4e559dc0d6606..ba7f3a23db65e77a0527d18a5e01d5609654cb04 100644
--- a/sched/sched_getstreams.c
+++ b/sched/sched_getstreams.c
@@ -68,9 +68,9 @@
  *
  ************************************************************/
 
-struct streamlist *sched_getstreams(void)
+FAR struct streamlist *sched_getstreams(void)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   return rtcb->streams;
 } 
 
diff --git a/sched/sched_gettcb.c b/sched/sched_gettcb.c
index 7073b796a5376e74bb0005ded2e70b5474d6459f..7f65f9342db8e380fe4a8aa45ead5db5575b6807 100644
--- a/sched/sched_gettcb.c
+++ b/sched/sched_gettcb.c
@@ -75,9 +75,9 @@
  *
  ************************************************************/
 
-_TCB *sched_gettcb(pid_t pid)
+FAR _TCB *sched_gettcb(pid_t pid)
 {
-  _TCB *ret = NULL;
+  FAR _TCB *ret = NULL;
   int hash_ndx;
 
   /* Verify that the PID is within range */
@@ -102,3 +102,4 @@ _TCB *sched_gettcb(pid_t pid)
 
   return ret;
 }
+
diff --git a/sched/sched_mergepending.c b/sched/sched_mergepending.c
index db03bccc3367657e52893289b09f2b2b4b539da5..ab61db6efbb29bea9ca908f7de06220ef663b25a 100644
--- a/sched/sched_mergepending.c
+++ b/sched/sched_mergepending.c
@@ -90,19 +90,19 @@
 
 boolean sched_mergepending(void)
 {
-  _TCB *pndtcb;
-  _TCB *pndnext;
-  _TCB *rtrtcb;
-  _TCB *rtrprev;
+  FAR _TCB *pndtcb;
+  FAR _TCB *pndnext;
+  FAR _TCB *rtrtcb;
+  FAR _TCB *rtrprev;
   boolean ret = FALSE;
 
   /* Initialize the inner search loop */
 
-  rtrtcb = (_TCB*)g_readytorun.head;
+  rtrtcb = (FAR _TCB*)g_readytorun.head;
 
   /* Process every TCB in the g_pendingtasks list */
 
-  for (pndtcb = (_TCB*)g_pendingtasks.head; pndtcb; pndtcb = pndnext)
+  for (pndtcb = (FAR _TCB*)g_pendingtasks.head; pndtcb; pndtcb = pndnext)
     {
       pndnext = pndtcb->flink;
 
@@ -137,7 +137,7 @@ boolean sched_mergepending(void)
               pndtcb->flink = rtrtcb;
               pndtcb->blink = NULL;
               rtrtcb->blink = pndtcb;
-              g_readytorun.head = (dq_entry_t*)pndtcb;
+              g_readytorun.head = (FAR dq_entry_t*)pndtcb;
               rtrtcb->task_state = TSTATE_TASK_READYTORUN;
               pndtcb->task_state = TSTATE_TASK_RUNNING;
               ret = TRUE;
diff --git a/sched/sched_processtimer.c b/sched/sched_processtimer.c
index bb56dbacb687989ff63ca9645f9e8c423a769712..eff439a5bcca6565392ff7f4da94897dd3901a46 100644
--- a/sched/sched_processtimer.c
+++ b/sched/sched_processtimer.c
@@ -42,6 +42,7 @@
  ************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 
 #if CONFIG_RR_INTERVAL > 0
diff --git a/sched/sched_releasetcb.c b/sched/sched_releasetcb.c
index ffbfc6c5830df7f8eb160f4c176cc509b76143fa..5e644839da72d3a5ee95999b0e1cf3807e40affa 100644
--- a/sched/sched_releasetcb.c
+++ b/sched/sched_releasetcb.c
@@ -90,7 +90,7 @@ static void sched_releasepid(pid_t pid)
  *
  ************************************************************/
 
-int sched_releasetcb(_TCB *tcb)
+int sched_releasetcb(FAR _TCB *tcb)
 {
   int ret = OK;
   int i;
@@ -138,5 +138,3 @@ int sched_releasetcb(_TCB *tcb)
   return ret;
 }
 
-
-
diff --git a/sched/sched_removeblocked.c b/sched/sched_removeblocked.c
index f3ed363ae00c20985afb7995ea441a2c3c7ee593..2b9294003e66934c6f3fc251e6f66ee6b684d1c8 100644
--- a/sched/sched_removeblocked.c
+++ b/sched/sched_removeblocked.c
@@ -90,7 +90,7 @@
  *
  ************************************************************/
 
-void sched_removeblocked(_TCB *btcb)
+void sched_removeblocked(FAR _TCB *btcb)
 {
   tstate_t task_state = btcb->task_state;
 
@@ -103,7 +103,7 @@ void sched_removeblocked(_TCB *btcb)
    * with this state
    */
 
-  dq_rem((dq_entry_t*)btcb, g_tasklisttable[task_state].list);
+  dq_rem((FAR dq_entry_t*)btcb, g_tasklisttable[task_state].list);
 
   /* Make sure the TCB's state corresponds to not being in
    * any list
@@ -111,3 +111,4 @@ void sched_removeblocked(_TCB *btcb)
 
   btcb->task_state = TSTATE_TASK_INVALID;
 }
+
diff --git a/sched/sched_removereadytorun.c b/sched/sched_removereadytorun.c
index 24057f3b72591ae5286c7e1854feeb573b7a663c..1c17feba0649eaced1ba0213756d02b0920302b6 100644
--- a/sched/sched_removereadytorun.c
+++ b/sched/sched_removereadytorun.c
@@ -87,7 +87,7 @@
  *   the head of the g_readytorun list is changed.
  ************************************************************/
 
-boolean sched_removereadytorun(_TCB *rtcb)
+boolean sched_removereadytorun(FAR _TCB *rtcb)
 {
   boolean ret = FALSE;
 
@@ -110,7 +110,7 @@ boolean sched_removereadytorun(_TCB *rtcb)
 
   /* Remove the TCB from the ready-to-run list */
 
-  dq_rem((dq_entry_t*)rtcb, &g_readytorun);
+  dq_rem((FAR dq_entry_t*)rtcb, &g_readytorun);
 
   rtcb->task_state = TSTATE_TASK_INVALID;
   return ret;
diff --git a/sched/sched_rrgetinterval.c b/sched/sched_rrgetinterval.c
index 8dfe99ff35152ea6b26fd65161d653320318dd82..dff4ebb4cd0445dde607e4efefc28c48fb2451f8 100644
--- a/sched/sched_rrgetinterval.c
+++ b/sched/sched_rrgetinterval.c
@@ -106,7 +106,7 @@
 int sched_rr_get_interval(pid_t pid, struct timespec *interval)
 {
 #if CONFIG_RR_INTERVAL > 0
-  _TCB  *rrtcb;
+  FAR _TCB  *rrtcb;
 
   /* If pid is zero, the timeslice for the calling process is
    * written into 'interval.'
@@ -114,7 +114,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval)
 
   if (!pid)
     {
-      rrtcb = (_TCB*)g_readytorun.head;
+      rrtcb = (FAR _TCB*)g_readytorun.head;
     }
 
   /* Return a special error code on invalid PID */
diff --git a/sched/sched_setparam.c b/sched/sched_setparam.c
index a1e5af97f002c8e9cb40dbadd51c4dbae99a6125..c9a935a4dddba51d8de5ea990b6c6258d5b1f9a4 100644
--- a/sched/sched_setparam.c
+++ b/sched/sched_setparam.c
@@ -105,8 +105,8 @@
 
 int sched_setparam(pid_t pid, const struct sched_param *param)
 {
-  _TCB      *rtcb;
-  _TCB      *tcb;
+  FAR _TCB  *rtcb;
+  FAR _TCB  *tcb;
   tstate_t   task_state;
   irqstate_t saved_state;
   int        sched_priority = param->sched_priority;
@@ -129,7 +129,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
 
   /* Check if the task to reprioritize is the calling task */
 
-  rtcb = (_TCB*)g_readytorun.head;
+  rtcb = (FAR _TCB*)g_readytorun.head;
   if (pid == 0 || pid == rtcb->pid)
     {
       tcb = rtcb;
@@ -236,7 +236,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
           {
             /* Remove the TCB from the prioritized task list */
 
-            dq_rem((dq_entry_t*)tcb, g_tasklisttable[task_state].list);
+            dq_rem((FAR dq_entry_t*)tcb, g_tasklisttable[task_state].list);
 
             /* Change the task priority */
 
diff --git a/sched/sched_setscheduler.c b/sched/sched_setscheduler.c
index 7d1b11ba4869c16c8fc31d6c3e0e1dff7d9f7563..4d4978a62d831d391e679bd9119074ac1be157ed 100644
--- a/sched/sched_setscheduler.c
+++ b/sched/sched_setscheduler.c
@@ -110,7 +110,7 @@
 int sched_setscheduler(pid_t pid, int policy,
                        const struct sched_param *param)
 {
-  _TCB *tcb;
+  FAR _TCB *tcb;
 #if CONFIG_RR_INTERVAL > 0
   irqstate_t saved_state;
 #endif
@@ -186,3 +186,4 @@ int sched_setscheduler(pid_t pid, int policy,
       return SCHED_FIFO;
     }
 }
+
diff --git a/sched/sched_setupidlefiles.c b/sched/sched_setupidlefiles.c
index c8be5478c8cdd1aca889667f6108c1dfb88d6e99..29d5dd3e04cdbe7303880c562e40569490a03548 100644
--- a/sched/sched_setupidlefiles.c
+++ b/sched/sched_setupidlefiles.c
@@ -71,7 +71,7 @@
  *
  ************************************************************/
 
-int sched_setupidlefiles(_TCB *tcb)
+int sched_setupidlefiles(FAR _TCB *tcb)
 {
   int fd;
 
diff --git a/sched/sched_setuppthreadfiles.c b/sched/sched_setuppthreadfiles.c
index 0935b487d8018f2b182f274f6aa8d0e657a7b276..5cc20c6d14883de3712efac4b231c40ba12837fc 100644
--- a/sched/sched_setuppthreadfiles.c
+++ b/sched/sched_setuppthreadfiles.c
@@ -71,9 +71,9 @@
  *
  ************************************************************/
 
-int sched_setuppthreadfiles(_TCB *tcb)
+int sched_setuppthreadfiles(FAR _TCB *tcb)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
 
   /* The child thread inherits the parent file descriptors */
 
diff --git a/sched/sched_setupstreams.c b/sched/sched_setupstreams.c
index 325ba92e985cca587beccd0ef561cd6679065d19..97509fc68cf2afe014caa4131f1e8053124503ef 100644
--- a/sched/sched_setupstreams.c
+++ b/sched/sched_setupstreams.c
@@ -53,7 +53,7 @@
  * Public Functions
  ************************************************************/
 
-int sched_setupstreams(_TCB *tcb)
+int sched_setupstreams(FAR _TCB *tcb)
 {
   /* Allocate file strems for the TCB */
 
diff --git a/sched/sched_setuptaskfiles.c b/sched/sched_setuptaskfiles.c
index 269e98e51f1209dfe8c77303099a5fb27bf8bb93..1753980313e8249787232064c46125f654c8bfee 100644
--- a/sched/sched_setuptaskfiles.c
+++ b/sched/sched_setuptaskfiles.c
@@ -71,10 +71,10 @@
  *
  ************************************************************/
 
-int sched_setuptaskfiles(_TCB *tcb)
+int sched_setuptaskfiles(FAR _TCB *tcb)
 {
 #ifdef CONFIG_DEV_CONSOLE
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   int i;
 #endif /* CONFIG_DEV_CONSOLE */
 
diff --git a/sched/sched_yield.c b/sched/sched_yield.c
index e91f8ecf6b516c9eecf7f88ac3cc6d9dc7656ffb..ae4db71781b8b0a1fae990a202507ac76df7ded5 100644
--- a/sched/sched_yield.c
+++ b/sched/sched_yield.c
@@ -90,7 +90,7 @@
 
 int sched_yield (void)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
   struct sched_param param;
 
   /* This equivalent to just resetting the task priority to
diff --git a/sched/sem_close.c b/sched/sem_close.c
index 3113b5156b662ee9f54ba804b853de0052fab6a3..9c278fb5825b479634782ae22c8b9aa82dd6c5a3 100644
--- a/sched/sem_close.c
+++ b/sched/sem_close.c
@@ -101,9 +101,9 @@
  *
  ************************************************************/
 
-int sem_close (sem_t *sem)
+int sem_close(FAR sem_t *sem)
 {
-  nsem_t *psem;
+  FAR nsem_t *psem;
   int ret = ERROR;
 
   /* Verify the inputs */
@@ -114,7 +114,7 @@ int sem_close (sem_t *sem)
 
       /* Search the list of named semaphores */
 
-      for (psem = (nsem_t*)g_nsems.head;
+      for (psem = (FAR nsem_t*)g_nsems.head;
            ((psem) && (sem != &psem->sem));
            psem = psem->flink);
 
@@ -132,7 +132,7 @@ int sem_close (sem_t *sem)
 
           if (!psem->nconnect && psem->unlinked)
             {
-              dq_rem((dq_entry_t*)psem, &g_nsems);
+              dq_rem((FAR dq_entry_t*)psem, &g_nsems);
               sched_free(psem);
             }
           ret = OK;
@@ -142,3 +142,4 @@ int sem_close (sem_t *sem)
 
   return ret;
 }
+
diff --git a/sched/sem_findnamed.c b/sched/sem_findnamed.c
index d513f7a31fbbdcc087d1c69f69a1c4dea61d7351..f626da42d632f3639c20c0b6f1f6c7c7b90f35e0 100644
--- a/sched/sem_findnamed.c
+++ b/sched/sem_findnamed.c
@@ -84,13 +84,13 @@
  *
  ************************************************************/
 
-nsem_t *sem_findnamed(const char *name)
+FAR nsem_t *sem_findnamed(const char *name)
 {
-  nsem_t *psem;
+  FAR nsem_t *psem;
 
   /* Search the list of named semaphores */
 
-  for (psem = (nsem_t*)g_nsems.head; (psem); psem = psem->flink)
+  for (psem = (FAR nsem_t*)g_nsems.head; (psem); psem = psem->flink)
     {
       if (!strcmp(name, psem->name))
         {
diff --git a/sched/sem_internal.h b/sched/sem_internal.h
index 460b358fc618dffcfec5b9af6cb49711ecdfab9e..9908d6e4c82638c514dcd444689c486cd649ae83 100644
--- a/sched/sem_internal.h
+++ b/sched/sem_internal.h
@@ -58,12 +58,12 @@
 
 struct nsem_s
 {
-  struct nsem_s *flink;         /* Forward link */
-  struct nsem_s *blink;         /* Backward link */
-  uint16         nconnect;      /* Number of connections to semaphore */
-  char          *name;          /* Semaphore name (NULL if un-named) */
-  boolean        unlinked;      /* TRUE if the semaphore has been unlinked */
-  sem_t          sem;           /* The semaphore itself */
+  FAR struct nsem_s *flink;     /* Forward link */
+  FAR struct nsem_s *blink;     /* Backward link */
+  uint16             nconnect;  /* Number of connections to semaphore */
+  FAR char          *name;      /* Semaphore name (NULL if un-named) */
+  boolean            unlinked;  /* TRUE if the semaphore has been unlinked */
+  sem_t              sem;       /* The semaphore itself */
 };
 typedef struct nsem_s nsem_t;
 
@@ -87,8 +87,8 @@ extern "C" {
 #endif
 
 EXTERN void weak_function sem_initialize(void);
-EXTERN void               sem_waitirq(_TCB *wtcb);
-EXTERN nsem_t            *sem_findnamed(const char *name);
+EXTERN void               sem_waitirq(FAR _TCB *wtcb);
+EXTERN FAR nsem_t        *sem_findnamed(const char *name);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/sched/sem_open.c b/sched/sem_open.c
index 6a8c38a4cb405fc90e812cd7a0dcb3ed50d0ca62..e9f6335c6e958daae9c842c7f35005325a0dd278 100644
--- a/sched/sem_open.c
+++ b/sched/sem_open.c
@@ -114,15 +114,11 @@
  *
  ************************************************************/
 
-sem_t *sem_open (const char *name, int oflag, ...)
+FAR sem_t *sem_open (const char *name, int oflag, ...)
 {
   int          namelen;
-  nsem_t      *psem;
-#ifdef CONFIG_CAN_CAST_POINTERS
-  sem_t       *sem = (sem_t*)ERROR;
-#else
-  sem_t       *sem = get_errorptr();
-#endif
+  FAR nsem_t  *psem;
+  FAR sem_t   *sem = (FAR sem_t*)ERROR;
   va_list      arg;          /* Points to each un-named argument */
   mode_t       mode;         /* Creation mode parameter (ignored) */
   unsigned int value;        /* Semaphore value parameter */
@@ -178,7 +174,7 @@ sem_t *sem_open (const char *name, int oflag, ...)
                 {
                   /* Allocate memory for the new semaphore */
 
-                  psem = (nsem_t*)kmalloc((sizeof(nsem_t) + namelen + 1));
+                  psem = (FAR nsem_t*)kmalloc((sizeof(nsem_t) + namelen + 1));
                   if (psem)
                     {
                       /* Initialize the named semaphore */
@@ -188,14 +184,14 @@ sem_t *sem_open (const char *name, int oflag, ...)
 
                       psem->nconnect = 1;
                       psem->unlinked = FALSE;
-                      psem->name = (char*)psem + sizeof(nsem_t);
+                      psem->name = (FAR char*)psem + sizeof(nsem_t);
                       strcpy(psem->name, name);
 
                       /* Add the new semaphore to the list of named
                        * semaphores
                        */
 
-                      dq_addfirst((dq_entry_t*)psem, &g_nsems);
+                      dq_addfirst((FAR dq_entry_t*)psem, &g_nsems);
                     }
 
                   /* Clean-up variable argument stuff */
@@ -209,3 +205,4 @@ sem_t *sem_open (const char *name, int oflag, ...)
 
   return sem;
 }
+
diff --git a/sched/sem_post.c b/sched/sem_post.c
index 348e88c808f081f5d6541c994144d1d9f97d5665..3b4fac368443ffdebf1f9042baaeae7cbe75fc6e 100644
--- a/sched/sem_post.c
+++ b/sched/sem_post.c
@@ -104,9 +104,9 @@
  *
  ************************************************************/
 
-int sem_post (sem_t *sem)
+int sem_post(sem_t *sem)
 {
-  _TCB      *stcb;
+  FAR _TCB  *stcb;
   STATUS     ret = ERROR;
   irqstate_t saved_state;
 
@@ -138,7 +138,7 @@ int sem_post (sem_t *sem)
            * that we want.
            */
 
-          for (stcb = (_TCB*)g_waitingforsemaphore.head;
+          for (stcb = (FAR _TCB*)g_waitingforsemaphore.head;
                ((stcb) && (stcb->waitsem != sem));
                stcb = stcb->flink);
 
diff --git a/sched/sem_unlink.c b/sched/sem_unlink.c
index 467db622e9338a8c1b533221eb4d4d92c2ef3c84..cc249ff8db7d605eda05954944a791e336687f48 100644
--- a/sched/sem_unlink.c
+++ b/sched/sem_unlink.c
@@ -95,10 +95,10 @@
  *
  ************************************************************/
 
-int sem_unlink (const char *name)
+int sem_unlink(const char *name)
 {
-  nsem_t *psem;
-  int     ret = ERROR;
+  FAR nsem_t *psem;
+  int         ret = ERROR;
 
   /* Verify the input values */
 
@@ -119,7 +119,7 @@ int sem_unlink (const char *name)
            */
           if (!psem->nconnect)
             {
-              dq_rem((dq_entry_t*)psem, &g_nsems);
+              dq_rem((FAR dq_entry_t*)psem, &g_nsems);
               sched_free(psem);
             }
 
@@ -139,3 +139,4 @@ int sem_unlink (const char *name)
 
   return ret;
 }
+
diff --git a/sched/sem_wait.c b/sched/sem_wait.c
index 78aa7d5e93c10861b03a7474dcbe953659fe65da..7893b39ba04e01c9273cbc5b3eaf5deaf45444f5 100644
--- a/sched/sem_wait.c
+++ b/sched/sem_wait.c
@@ -97,9 +97,9 @@
  *
  ************************************************************/
 
-int sem_wait (sem_t *sem)
+int sem_wait(sem_t *sem)
 {
-  _TCB      *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB  *rtcb = (FAR _TCB*)g_readytorun.head;
   int        ret = ERROR;
   irqstate_t saved_state;
 
@@ -172,3 +172,4 @@ int sem_wait (sem_t *sem)
 
   return ret;
 }
+
diff --git a/sched/sem_waitirq.c b/sched/sem_waitirq.c
index 810663732af8373f7516b4a5cde5b8a957cbf47c..b7cbdce21a917e116a0d79004ebb2e5cbbe797c1 100644
--- a/sched/sem_waitirq.c
+++ b/sched/sem_waitirq.c
@@ -92,7 +92,7 @@
  *
  ************************************************************/
 
-void sem_waitirq (_TCB *wtcb)
+void sem_waitirq(FAR _TCB *wtcb)
 {
   irqstate_t saved_state;
 
@@ -126,3 +126,4 @@ void sem_waitirq (_TCB *wtcb)
 
   irqrestore(saved_state);
 }
+
diff --git a/sched/sig_action.c b/sched/sig_action.c
index 7f9a1c343cc484d6b83f80e307a477606735ac17..f7fe7cdb579fcf0ca5a397e04d9ea105eca67ec5 100644
--- a/sched/sig_action.c
+++ b/sched/sig_action.c
@@ -77,13 +77,13 @@
  *
  ************************************************************/
 
-static sigactq_t *sig_allocateaction(void)
+static FAR sigactq_t *sig_allocateaction(void)
 {
-  sigactq_t *sigact;
+  FAR sigactq_t *sigact;
 
   /* Try to get the signal action structure from the free list */
 
-  sigact = (sigactq_t*)sq_remfirst(&g_sigfreeaction);
+  sigact = (FAR sigactq_t*)sq_remfirst(&g_sigfreeaction);
 
   /* Check if we got one. */
 
@@ -95,7 +95,7 @@ static sigactq_t *sig_allocateaction(void)
 
       /* And try again */
 
-      sigact = (sigactq_t*)sq_remfirst(&g_sigfreeaction);
+      sigact = (FAR sigactq_t*)sq_remfirst(&g_sigfreeaction);
       if (!sigact)
         {
           PANIC(OSERR_OUTOFMEMORY);
@@ -171,9 +171,9 @@ static sigactq_t *sig_allocateaction(void)
 int sigaction(int signo, const struct sigaction *act,
               struct sigaction *oact)
 {
-  _TCB      *rtcb = (_TCB*)g_readytorun.head;
-  sigactq_t *sigact;
-  int        ret = ERROR;  /* Assume failure */
+  FAR _TCB      *rtcb = (FAR _TCB*)g_readytorun.head;
+  FAR sigactq_t *sigact;
+  int            ret = ERROR;  /* Assume failure */
 
   /* Since sigactions can only be installed from the running
    * thread of execution, no special precautions should be
@@ -229,7 +229,7 @@ int sigaction(int signo, const struct sigaction *act,
 
               /* Add the new sigaction to sigactionq */
 
-              sq_addlast((sq_entry_t*)sigact, &rtcb->sigactionq);
+              sq_addlast((FAR sq_entry_t*)sigact, &rtcb->sigactionq);
             }
         }
 
@@ -250,7 +250,7 @@ int sigaction(int signo, const struct sigaction *act,
             {
               /* Remove the old sigaction from sigactionq */
 
-              sq_rem((sq_entry_t*)sigact, &rtcb->sigactionq);
+              sq_rem((FAR sq_entry_t*)sigact, &rtcb->sigactionq);
 
               /* And deallocate it */
 
@@ -270,9 +270,9 @@ int sigaction(int signo, const struct sigaction *act,
  *
  ************************************************************/
 
-void sig_releaseaction(sigactq_t *sigact)
+void sig_releaseaction(FAR sigactq_t *sigact)
 {
   /* Just put it back on the free list */
 
-  sq_addlast((sq_entry_t*)sigact, &g_sigfreeaction);
+  sq_addlast((FAR sq_entry_t*)sigact, &g_sigfreeaction);
 }
diff --git a/sched/sig_allocatependingsigaction.c b/sched/sig_allocatependingsigaction.c
index 610596457459247150d6b92b60097c5964cdd957..5356058cfa90409a28881136ba2311389b837b87 100644
--- a/sched/sig_allocatependingsigaction.c
+++ b/sched/sig_allocatependingsigaction.c
@@ -75,9 +75,9 @@
  *   Allocate a new element for the pending signal action queue
  ************************************************************/
 
-sigq_t *sig_allocatependingsigaction(void)
+FAR sigq_t *sig_allocatependingsigaction(void)
 {
-  sigq_t    *sigq;
+  FAR sigq_t    *sigq;
   irqstate_t saved_state;
 
   /* Check if we were called from an interrupt handler. */
@@ -86,7 +86,7 @@ sigq_t *sig_allocatependingsigaction(void)
     {
       /* Try to get the pending signal action structure from the free list */
 
-      sigq = (sigq_t*)sq_remfirst(&g_sigpendingaction);
+      sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingaction);
 
       /* If so, then try the special list of structures reserved for
        * interrupt handlers
@@ -94,7 +94,7 @@ sigq_t *sig_allocatependingsigaction(void)
 
       if (!sigq)
         {
-          sigq = (sigq_t*)sq_remfirst(&g_sigpendingirqaction);
+          sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingirqaction);
         }
     }
 
@@ -106,7 +106,7 @@ sigq_t *sig_allocatependingsigaction(void)
       /* Try to get the pending signal action structure from the free list */
 
       saved_state = irqsave();
-      sigq = (sigq_t*)sq_remfirst(&g_sigpendingaction);
+      sigq = (FAR sigq_t*)sq_remfirst(&g_sigpendingaction);
       irqrestore(saved_state);
 
       /* Check if we got one. */
@@ -117,7 +117,7 @@ sigq_t *sig_allocatependingsigaction(void)
 
           if (!sigq)
             {
-              sigq = (sigq_t *)kmalloc((sizeof (sigq_t)));
+              sigq = (FAR sigq_t *)kmalloc((sizeof (sigq_t)));
             }
 
           /* Check if we got an allocated message */
diff --git a/sched/sig_cleanup.c b/sched/sig_cleanup.c
index d9e1073dffa039aef5f2f0ceefad9c47f166985d..019e7fbe505e8625b8973dc8d96300adeda7cc0e 100644
--- a/sched/sig_cleanup.c
+++ b/sched/sig_cleanup.c
@@ -76,36 +76,36 @@
  * to perform this action.
  ************************************************************/
 
-void sig_cleanup(_TCB *stcb)
+void sig_cleanup(FAR _TCB *stcb)
 {
-  sigactq_t  *sigact;
-  sigq_t     *sigq;
-  sigpendq_t *sigpend;
+  FAR sigactq_t  *sigact;
+  FAR sigq_t     *sigq;
+  FAR sigpendq_t *sigpend;
 
   /* Deallocate all entries in the list of signal actions */
 
-  while ((sigact = (sigactq_t*)sq_remfirst(&stcb->sigactionq)) != NULL)
+  while ((sigact = (FAR sigactq_t*)sq_remfirst(&stcb->sigactionq)) != NULL)
     {
       sig_releaseaction(sigact);
     }
 
   /* Deallocate all entries in the list of pending signals */
 
-  while ((sigpend = (sigpendq_t*)sq_remfirst(&stcb->sigpendingq)) != NULL)
+  while ((sigpend = (FAR sigpendq_t*)sq_remfirst(&stcb->sigpendingq)) != NULL)
     {
       sig_releasependingsignal(sigpend);
     }
 
   /* Deallocate all entries in the list of pending signal actions */
 
-  while ((sigq = (sigq_t*)sq_remfirst(&stcb->sigpendactionq)) != NULL)
+  while ((sigq = (FAR sigq_t*)sq_remfirst(&stcb->sigpendactionq)) != NULL)
     {
       sig_releasependingsigaction(sigq);
     }
 
   /* Deallocate all entries in the list of posted signal actions */
 
-  while ((sigq = (sigq_t*)sq_remfirst(&stcb->sigpostedq)) != NULL)
+  while ((sigq = (FAR sigq_t*)sq_remfirst(&stcb->sigpostedq)) != NULL)
     {
       sig_releasependingsigaction(sigq);
     }
diff --git a/sched/sig_deliver.c b/sched/sig_deliver.c
index c106337979adb58a4716232dcf7dd30e9d0c688c..5eb24d307b2f7237f1703f2104ca345daea71e4b 100644
--- a/sched/sig_deliver.c
+++ b/sched/sig_deliver.c
@@ -81,14 +81,14 @@
  *
  ************************************************************/
 
-void sig_deliver(_TCB *stcb)
+void sig_deliver(FAR _TCB *stcb)
 {
-  pid_t      rpid;
-  sigq_t    *sigq;
-  sigq_t    *next;
-  sigset_t   savesigprocmask;
-  irqstate_t saved_state;
-  int        saved_errno;
+  pid_t       rpid;
+  FAR sigq_t *sigq;
+  FAR sigq_t *next;
+  sigset_t    savesigprocmask;
+  irqstate_t  saved_state;
+  int         saved_errno;
 
   sched_lock();
 
@@ -100,7 +100,7 @@ void sig_deliver(_TCB *stcb)
    */
 
   saved_errno = stcb->errno;
-  for (sigq = (sigq_t*)stcb->sigpendactionq.head; (sigq); sigq = next)
+  for (sigq = (FAR sigq_t*)stcb->sigpendactionq.head; (sigq); sigq = next)
     {
       next = sigq->flink;
       dbg("sig_deliver: Sending signal sigq=0x%x\n", sigq);
@@ -111,8 +111,8 @@ void sig_deliver(_TCB *stcb)
        */
 
       saved_state = irqsave();
-      sq_rem((sq_entry_t*)sigq, &(stcb->sigpendactionq));
-      sq_addlast((sq_entry_t*)sigq, &(stcb->sigpostedq));
+      sq_rem((FAR sq_entry_t*)sigq, &(stcb->sigpendactionq));
+      sq_addlast((FAR sq_entry_t*)sigq, &(stcb->sigpostedq));
       irqrestore(saved_state);
 
       /* Call the signal handler (unless the signal was cancelled)
@@ -150,7 +150,7 @@ void sig_deliver(_TCB *stcb)
       /* Remove the signal from the sigpostedq */
 
       saved_state = irqsave();
-      sq_rem((sq_entry_t*)sigq, &(stcb->sigpostedq));
+      sq_rem((FAR sq_entry_t*)sigq, &(stcb->sigpostedq));
       irqrestore(saved_state);
 
       /* Then deallocate it */
diff --git a/sched/sig_findaction.c b/sched/sig_findaction.c
index 98df313ec2774119fd924fba312f027f666d12c0..be5675d62f55dc9130ab5c493fef4202b9abbaa0 100644
--- a/sched/sig_findaction.c
+++ b/sched/sig_findaction.c
@@ -72,28 +72,28 @@
  *
  ************************************************************/
 
-sigactq_t *sig_findaction(_TCB *stcb, int signo)
+FAR sigactq_t *sig_findaction(FAR _TCB *stcb, int signo)
 {
-   sigactq_t *sigact = NULL;
+  FAR sigactq_t *sigact = NULL;
 
-   /* Verify the caller's sanity */
+  /* Verify the caller's sanity */
 
-   if (stcb)
-     {
-       /* Sigactions can only be assigned to the currently executing
-        * thread.  So, a simple lock ought to give us sufficient
-        * protection.
-        */
+  if (stcb)
+    {
+      /* Sigactions can only be assigned to the currently executing
+       * thread.  So, a simple lock ought to give us sufficient
+       * protection.
+       */
 
-       sched_lock();
+      sched_lock();
 
-       /* Seach the list for a sigaction on this signal */
+      /* Seach the list for a sigaction on this signal */
 
-       for(sigact = (sigactq_t*)stcb->sigactionq.head;
-           ((sigact) && (sigact->signo != signo));
-           sigact = sigact->flink);
+      for(sigact = (FAR sigactq_t*)stcb->sigactionq.head;
+          ((sigact) && (sigact->signo != signo));
+          sigact = sigact->flink);
 
-       sched_unlock();
+      sched_unlock();
    }
 
    return sigact;
diff --git a/sched/sig_initialize.c b/sched/sig_initialize.c
index 1c1e8c23cb9001b68ae9a098ab8ea7be8ecf486c..d3bd1086045612ef66e66a682424048646a18b52 100644
--- a/sched/sig_initialize.c
+++ b/sched/sig_initialize.c
@@ -124,10 +124,10 @@ static sigpendq_t *g_sigpendingirqsignalalloc;
  * Private Function Prototypes
  ************************************************************/
 
-static sigq_t     *sig_allocateblock(sq_queue_t *sigList, uint16 nSigs,
-                                     ubyte sigType);
-static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *sigList,
-                                                  uint16 nSigs, ubyte sigType);
+static sigq_t     *sig_allocateblock(sq_queue_t *siglist, uint16 nsigs,
+                                     ubyte sigtype);
+static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist,
+                                                  uint16 nsigs, ubyte sigtype);
 
 /************************************************************
  * Private Functions
@@ -142,8 +142,8 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *sigList,
  *
  ************************************************************/
 
-static sigq_t *sig_allocateblock(sq_queue_t *sigList, uint16 nSigs,
-                                 ubyte sigType)
+static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16 nsigs,
+                                 ubyte sigtype)
 {
   sigq_t *sigqalloc;
   sigq_t *sigq;
@@ -151,13 +151,13 @@ static sigq_t *sig_allocateblock(sq_queue_t *sigList, uint16 nSigs,
 
   /* Allocate a block of pending signal actions */
 
-  sigqalloc = (sigq_t*)kmalloc((sizeof(sigq_t)) * nSigs);
+  sigqalloc = (sigq_t*)kmalloc((sizeof(sigq_t)) * nsigs);
 
   sigq = sigqalloc;
-  for (i = 0; i < nSigs; i++)
+  for (i = 0; i < nsigs; i++)
     {
-      sigq->type = sigType;
-      sq_addlast((sq_entry_t*)sigq++, sigList);
+      sigq->type = sigtype;
+      sq_addlast((FAR sq_entry_t*)sigq++, siglist);
     }
 
   return sigqalloc;
@@ -171,8 +171,8 @@ static sigq_t *sig_allocateblock(sq_queue_t *sigList, uint16 nSigs,
  * on the free list.
  ************************************************************/
 
-static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *sigList,
-                                           uint16 nSigs, ubyte sigType)
+static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist,
+                                           uint16 nsigs, ubyte sigtype)
 {
   sigpendq_t *sigpendalloc;
   sigpendq_t *sigpend;
@@ -181,13 +181,13 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *sigList,
   /* Allocate a block of pending signal structures  */
 
   sigpendalloc =
-     (sigpendq_t*)kmalloc((sizeof(sigpendq_t)) * nSigs);
+     (sigpendq_t*)kmalloc((sizeof(sigpendq_t)) * nsigs);
 
   sigpend = sigpendalloc;
-  for (i = 0; i < nSigs; i++)
+  for (i = 0; i < nsigs; i++)
     {
-      sigpend->type = sigType;
-      sq_addlast((sq_entry_t*)sigpend++, sigList);
+      sigpend->type = sigtype;
+      sq_addlast((FAR sq_entry_t*)sigpend++, siglist);
     }
 
   return sigpendalloc;
@@ -255,7 +255,7 @@ void sig_allocateactionblock(void)
   sigact = g_sigactionalloc;
   for (i = 0; i < NUM_SIGNAL_ACTIONS; i++)
     {
-      sq_addlast((sq_entry_t*)sigact++, &g_sigfreeaction);
+      sq_addlast((FAR sq_entry_t*)sigact++, &g_sigfreeaction);
     }
 }
 
diff --git a/sched/sig_internal.h b/sched/sig_internal.h
index b03b2ec0eba5dd3ac3a303c5851046858d124bda..8ae975e42962555dc1e10ccccdfb9b2d6a85095a 100644
--- a/sched/sig_internal.h
+++ b/sched/sig_internal.h
@@ -40,6 +40,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <queue.h>
 #include <sched.h>
 #include <nuttx/kmalloc.h>
@@ -75,9 +76,9 @@ typedef enum sigalloc_e sigalloc_t;
 
 struct sigactq
 {
-  struct sigactq   *flink;       /* Forward link */
-  struct sigaction  act;         /* Sigaction data */
-  ubyte             signo;       /* Signal associated with action */
+  FAR struct sigactq *flink;     /* Forward link */
+  struct sigaction act;          /* Sigaction data */
+  ubyte     signo;               /* Signal associated with action */
 };
 typedef struct sigactq  sigactq_t;
 
@@ -89,9 +90,9 @@ typedef struct sigactq  sigactq_t;
 
 struct sigpendq
 {
-  struct sigpendq *flink;        /* Forward link */
-  siginfo_t        info;         /* Signal information */
-  ubyte            type;         /* (Used to manage allocations) */
+  FAR struct sigpendq *flink;    /* Forward link */
+  siginfo_t info;                /* Signal information */
+  ubyte     type;                /* (Used to manage allocations) */
 };
 typedef struct sigpendq sigpendq_t;
 
@@ -101,15 +102,15 @@ typedef struct sigpendq sigpendq_t;
 
 struct sigq_s
 {
-  struct sigq_s   *flink;        /* Forward link */
+  FAR struct sigq_s *flink;      /* Forward link */
   union
   {
     void (*sighandler)(int signo, siginfo_t *info, void *context);
   } action;                      /* Signal action */
-  sigset_t         mask;         /* Additional signals to mask while the
+  sigset_t  mask;                /* Additional signals to mask while the
 				  * the signal-catching functin executes */
-  siginfo_t        info;         /* Signal information */
-  ubyte            type;         /* (Used to manage allocations) */
+  siginfo_t info;                /* Signal information */
+  ubyte     type;                /* (Used to manage allocations) */
 };
 typedef struct sigq_s sigq_t;
 
@@ -162,18 +163,18 @@ extern void               sig_allocateactionblock(void);
 
 /* sig_action.c */
 
-extern void               sig_releaseaction(sigactq_t *sigact);
+extern void               sig_releaseaction(FAR sigactq_t *sigact);
 
 /* sig_pending.c */
 
-extern sigset_t           sig_pendingset(_TCB *stcb);
+extern sigset_t           sig_pendingset(FAR _TCB *stcb);
 
 /* In files of the same name */
 
-extern sigq_t            *sig_allocatependingsigaction(void);
-extern void               sig_cleanup(_TCB *stcb);
-extern void               sig_deliver(_TCB *stcb);
-extern sigactq_t         *sig_findaction(_TCB *stcb, int signo);
+extern FAR sigq_t        *sig_allocatependingsigaction(void);
+extern void               sig_cleanup(FAR _TCB *stcb);
+extern void               sig_deliver(FAR _TCB *stcb);
+extern FAR sigactq_t     *sig_findaction(FAR _TCB *stcb, int signo);
 extern int                sig_lowest(sigset_t *set);
 #ifdef CONFIG_CAN_PASS_STRUCTS
 extern int                sig_mqnotempty(int tid, int signo,
@@ -182,10 +183,10 @@ extern int                sig_mqnotempty(int tid, int signo,
 extern int                sig_mqnotempty(int tid, int signo,
                                          void *sival_ptr);
 #endif
-extern int                sig_received(_TCB *stcb, siginfo_t *info);
-extern void               sig_releasependingsigaction(sigq_t *sigq);
-extern void               sig_releasependingsignal(sigpendq_t *sigpend);
-extern sigpendq_t        *sig_removependingsignal(_TCB *stcb, int signo);
+extern int                sig_received(FAR _TCB *stcb, siginfo_t *info);
+extern void               sig_releasependingsigaction(FAR sigq_t *sigq);
+extern void               sig_releasependingsignal(FAR sigpendq_t *sigpend);
+extern FAR sigpendq_t    *sig_removependingsignal(FAR _TCB *stcb, int signo);
 extern void               sig_unmaskpendingsignal(void);
 
 #endif /* __SIG_INTERNAL_H */
diff --git a/sched/sig_mqnotempty.c b/sched/sig_mqnotempty.c
index ab395db2ea1af3172c775332e6ccce831941d6a4..a55d3138efd512d9be6e6175c09f0d25c2042699 100644
--- a/sched/sig_mqnotempty.c
+++ b/sched/sig_mqnotempty.c
@@ -37,6 +37,7 @@
  * Included Files
  ************************************************************/
 
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 #include <signal.h>
 #include <sched.h>
@@ -86,7 +87,7 @@ int sig_mqnotempty (int pid, int signo, const union sigval value)
 int sig_mqnotempty (int pid, int signo, void *sival_ptr)
 #endif
 {
-  _TCB     *stcb;
+  FAR _TCB *stcb;
   siginfo_t info;
   int       ret = ERROR;
 
diff --git a/sched/sig_pending.c b/sched/sig_pending.c
index 62b98f3cae6185084c5dd9f1f55d6f33807ae7a7..a2ee01d4e8d1b3482b185306ba602334540504a0 100644
--- a/sched/sig_pending.c
+++ b/sched/sig_pending.c
@@ -87,8 +87,8 @@
 
 int sigpending(sigset_t *set)
 {
-  _TCB *rtcb = (_TCB*)g_readytorun.head;
-  int   ret = ERROR;
+  FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
+  int       ret  = ERROR;
 
   if (set)
     {
@@ -106,16 +106,16 @@ int sigpending(sigset_t *set)
  *   Convert the list of pending signals into a signal set
  ************************************************************/
 
-sigset_t sig_pendingset(_TCB *stcb)
+sigset_t sig_pendingset(FAR _TCB *stcb)
 {
-  sigset_t    sigpendset;
-  sigpendq_t *sigpend;
-  irqstate_t  saved_state;
+  sigset_t        sigpendset;
+  FAR sigpendq_t *sigpend;
+  irqstate_t      saved_state;
 
   sigpendset = NULL_SIGNAL_SET;
 
   saved_state = irqsave();
-  for (sigpend = (sigpendq_t*)stcb->sigpendingq.head;
+  for (sigpend = (FAR sigpendq_t*)stcb->sigpendingq.head;
        (sigpend); sigpend = sigpend->flink)
     {
       sigaddset(&sigpendset, sigpend->info.si_signo);
diff --git a/sched/sig_procmask.c b/sched/sig_procmask.c
index dd5dd9eb8106a297e5745defc3e02ca871cc6c5c..339e6dda5358f53da482286b1a40a28a023a031c 100644
--- a/sched/sig_procmask.c
+++ b/sched/sig_procmask.c
@@ -114,7 +114,7 @@
 
 int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
 {
-  _TCB      *rtcb = (_TCB*)g_readytorun.head;
+  FAR _TCB  *rtcb = (FAR _TCB*)g_readytorun.head;
   sigset_t   oldsigprocmask;
   irqstate_t saved_state;
   int        ret = OK;
@@ -124,48 +124,57 @@ int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
   /* Return the old signal mask if requested */
 
   oldsigprocmask = rtcb->sigprocmask;
-  if (oset) *oset = oldsigprocmask;
+  if (oset)
+    {
+      *oset = oldsigprocmask;
+    }
 
   /* Modify the current signal mask if so requested */
-  if (set) {
-     /* Some of these operations are non-atomic.  We need to protect
-      * ourselves from attempts to process signals from interrupts */
 
-     saved_state = irqsave();
+  if (set)
+    {
+      /* Some of these operations are non-atomic.  We need to protect
+       * ourselves from attempts to process signals from interrupts
+       */
 
-     /* Okay, determine what we are supposed to do */
+      saved_state = irqsave();
 
-     switch (how) {
-        /* The resulting set is the union of the current set and the
-         * signal set pointed to by set. */
+      /* Okay, determine what we are supposed to do */
 
-         case SIG_BLOCK:
-           rtcb->sigprocmask |= *set;
-           break;
+      switch (how)
+        {
+          /* The resulting set is the union of the current set and the
+           * signal set pointed to by set.
+           */
 
-         /* The resulting set is the intersection of the current set and
-          * the complement of the signal set pointed to by _set. */
+          case SIG_BLOCK:
+            rtcb->sigprocmask |= *set;
+            break;
 
-         case SIG_UNBLOCK:
-           rtcb->sigprocmask &= ~(*set);
-           break;
+          /* The resulting set is the intersection of the current set and
+           * the complement of the signal set pointed to by _set.
+           */
 
-         /* The resulting set is the signal set pointed to by set. */
+          case SIG_UNBLOCK:
+            rtcb->sigprocmask &= ~(*set);
+            break;
 
-         case SIG_SETMASK:
-           rtcb->sigprocmask = *set;
-           break;
+          /* The resulting set is the signal set pointed to by set. */
 
-         default: 
-          ret = ERROR;
-          break;
-      } /* end switch */
+          case SIG_SETMASK:
+            rtcb->sigprocmask = *set;
+            break;
+
+          default: 
+            ret = ERROR;
+            break;
+        }
       irqrestore(saved_state);
 
       /* Now, process any pending signals that were just unmasked */
 
       sig_unmaskpendingsignal();
-   } /* end if */
+    }
 
    sched_unlock();
    return ret;
diff --git a/sched/sig_queue.c b/sched/sig_queue.c
index b9d71efcc63b2d78d0d630b328726cf50abaef43..dcae4e0a5b75651fb5b7ccbd17efca81d13e9070 100644
--- a/sched/sig_queue.c
+++ b/sched/sig_queue.c
@@ -38,6 +38,7 @@
  ************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/compiler.h>
 #include <sys/types.h>
 #include <signal.h>
 #include <debug.h>
@@ -103,7 +104,7 @@ int sigqueue (int pid, int signo, const union sigval value)
 int sigqueue(int pid, int signo, void *sival_ptr)
 #endif
 {
-  _TCB     *stcb;
+  FAR _TCB *stcb;
   siginfo_t info;
   int       ret = ERROR;
 
diff --git a/sched/sig_received.c b/sched/sig_received.c
index 922d4b778893981679e5f4733f21808e86e9a8d9..9df9e797cb6c5db69faffca643f2d04824d2b73e 100644
--- a/sched/sig_received.c
+++ b/sched/sig_received.c
@@ -76,12 +76,12 @@
  *
  ************************************************************/
 
-static int sig_queueaction(_TCB *stcb, siginfo_t *info)
+static int sig_queueaction(FAR _TCB *stcb, siginfo_t *info)
 {
-  sigactq_t *sigact;
-  sigq_t    *sigq;
-  irqstate_t saved_state;
-  int        ret = OK;
+  FAR sigactq_t *sigact;
+  FAR sigq_t    *sigq;
+  irqstate_t     saved_state;
+  int            ret = OK;
 
   sched_lock();
 
@@ -112,7 +112,7 @@ static int sig_queueaction(_TCB *stcb, siginfo_t *info)
            /* Put it at the end of the pending signals list */
 
            saved_state = irqsave();
-           sq_addlast((sq_entry_t*)sigq, &(stcb->sigpendactionq));
+           sq_addlast((FAR sq_entry_t*)sigq, &(stcb->sigpendactionq));
            irqrestore(saved_state);
         }
     }
@@ -129,10 +129,10 @@ static int sig_queueaction(_TCB *stcb, siginfo_t *info)
  *
  ************************************************************/
 
-static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo)
+static FAR sigpendq_t *sig_findpendingsignal(FAR _TCB *stcb, int signo)
 {
-  sigpendq_t *sigpend = NULL;
-  irqstate_t  saved_state;
+  FAR sigpendq_t *sigpend = NULL;
+  irqstate_t      saved_state;
 
   /* Verify the caller's sanity */
 
@@ -144,7 +144,7 @@ static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo)
 
       /* Seach the list for a sigpendion on this signal */
 
-      for(sigpend = (sigpendq_t*)stcb->sigpendingq.head;
+      for(sigpend = (FAR sigpendq_t*)stcb->sigpendingq.head;
          (sigpend && sigpend->info.si_signo != signo);
          sigpend = sigpend->flink);
       irqrestore(saved_state);
@@ -161,10 +161,10 @@ static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo)
  *
  ************************************************************/
 
-static sigpendq_t *sig_allocatependingsignal(void)
+static FAR sigpendq_t *sig_allocatependingsignal(void)
 {
-  sigpendq_t *sigpend;
-  irqstate_t  saved_state;
+  FAR sigpendq_t *sigpend;
+  irqstate_t      saved_state;
 
   /* Check if we were called from an interrupt handler. */
 
@@ -172,13 +172,13 @@ static sigpendq_t *sig_allocatependingsignal(void)
     {
       /* Try to get the pending signal structure from the free list */
 
-      sigpend = (sigpendq_t*)sq_remfirst(&g_sigpendingsignal);
+      sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingsignal);
 
       /* If so, then try the special list of structures reserved for
        * interrupt handlers
        */
 
-      sigpend = (sigpendq_t*)sq_remfirst(&g_sigpendingirqsignal);
+      sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingirqsignal);
     }
 
   /* If we were not called from an interrupt handler, then we are
@@ -189,18 +189,18 @@ static sigpendq_t *sig_allocatependingsignal(void)
       /* Try to get the pending signal structure from the free list */
 
       saved_state = irqsave();
-      sigpend = (sigpendq_t*)sq_remfirst(&g_sigpendingsignal);
+      sigpend = (FAR sigpendq_t*)sq_remfirst(&g_sigpendingsignal);
       irqrestore(saved_state);
 
       /* Check if we got one. */
 
       if (!sigpend)
         {
-          /* No...Try the resource pool */
+          /* No... Allocate the pending signal */
 
           if (!sigpend)
             {
-              sigpend = (sigpendq_t *)kmalloc((sizeof (sigpendq_t)));
+              sigpend = (FAR sigpendq_t *)kmalloc((sizeof (sigpendq_t)));
             }
 
           /* Check if we got an allocated message */
@@ -225,10 +225,10 @@ static sigpendq_t *sig_allocatependingsignal(void)
  * run-away sender cannot consume all of memory.
  ************************************************************/
 
-static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
+static FAR sigpendq_t *sig_addpendingsignal(FAR _TCB *stcb, siginfo_t *info)
 {
-  sigpendq_t *sigpend;
-  irqstate_t  saved_state;
+  FAR sigpendq_t *sigpend;
+  irqstate_t      saved_state;
 
   /* Check if the signal is already pending */
 
@@ -256,7 +256,7 @@ static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
           /* Add the structure to the pending signal list */
 
           saved_state = irqsave();
-          sq_addlast((sq_entry_t*)sigpend, &stcb->sigpendingq);
+          sq_addlast((FAR sq_entry_t*)sigpend, &stcb->sigpendingq);
           irqrestore(saved_state);
         }
     }
@@ -283,7 +283,7 @@ static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
  *
  ************************************************************/
 
-int sig_received(_TCB *stcb, siginfo_t *info)
+int sig_received(FAR _TCB *stcb, siginfo_t *info)
 {
   irqstate_t saved_state;
   int        ret = ERROR;
diff --git a/sched/sig_releasependingsigaction.c b/sched/sig_releasependingsigaction.c
index b25ee79e32690027ec20f066389df0758f753b26..9ddedc711f7b362fe51ea6d0b26137b1507abab2 100644
--- a/sched/sig_releasependingsigaction.c
+++ b/sched/sig_releasependingsigaction.c
@@ -74,7 +74,7 @@
  *
  ************************************************************/
 
-void sig_releasependingsigaction(sigq_t *sigq)
+void sig_releasependingsigaction(FAR sigq_t *sigq)
 {
   irqstate_t saved_state;
 
@@ -88,7 +88,7 @@ void sig_releasependingsigaction(sigq_t *sigq)
        * list from interrupt handlers. */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)sigq, &g_sigpendingaction);
+      sq_addlast((FAR sq_entry_t*)sigq, &g_sigpendingaction);
       irqrestore(saved_state);
    }
 
@@ -102,7 +102,7 @@ void sig_releasependingsigaction(sigq_t *sigq)
        * list from interrupt handlers. */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)sigq, &g_sigpendingirqaction);
+      sq_addlast((FAR sq_entry_t*)sigq, &g_sigpendingirqaction);
       irqrestore(saved_state);
    }
 
diff --git a/sched/sig_releasependingsignal.c b/sched/sig_releasependingsignal.c
index 43601d7db9dd5605fca40b72ca634ad842eeeed2..198c145dfe625f9ee9882eb76b032e96ea5eae07 100644
--- a/sched/sig_releasependingsignal.c
+++ b/sched/sig_releasependingsignal.c
@@ -82,7 +82,7 @@
  *   Deallocate a pending signal list entry
  ************************************************************/
 
-void sig_releasependingsignal(sigpendq_t *sigpend)
+void sig_releasependingsignal(FAR sigpendq_t *sigpend)
 {
   irqstate_t saved_state;
 
@@ -96,7 +96,7 @@ void sig_releasependingsignal(sigpendq_t *sigpend)
        * list from interrupt handlers. */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)sigpend, &g_sigpendingsignal);
+      sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingsignal);
       irqrestore(saved_state);
     }
 
@@ -111,7 +111,7 @@ void sig_releasependingsignal(sigpendq_t *sigpend)
        */
 
       saved_state = irqsave();
-      sq_addlast((sq_entry_t*)sigpend, &g_sigpendingirqsignal);
+      sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingirqsignal);
       irqrestore(saved_state);
    }
 
diff --git a/sched/sig_removependingsignal.c b/sched/sig_removependingsignal.c
index 917d6d7e1fffafa8ea1061b5fe061ac83dac8c70..c31c0bbe73d74b2e7999f193dba77d497d543e51 100644
--- a/sched/sig_removependingsignal.c
+++ b/sched/sig_removependingsignal.c
@@ -82,21 +82,21 @@
  *  Remove the specified signal from the signal pending list
  ************************************************************/
 
-sigpendq_t *sig_removependingsignal(_TCB *stcb, int signo)
+FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo)
 {
-  sigpendq_t *currsig;
-  sigpendq_t *prevsig;
+  FAR sigpendq_t *currsig;
+  FAR sigpendq_t *prevsig;
   irqstate_t  saved_state;
 
   saved_state = irqsave();
-  for (prevsig = NULL, currsig = (sigpendq_t*)stcb->sigpendingq.head;
+  for (prevsig = NULL, currsig = (FAR sigpendq_t*)stcb->sigpendingq.head;
        (currsig && currsig->info.si_signo != signo);
        prevsig = currsig, currsig = currsig->flink);
   if (currsig) 
     {
       if (prevsig)
         {
-          sq_remafter((sq_entry_t*)prevsig, &stcb->sigpendingq);
+          sq_remafter((FAR sq_entry_t*)prevsig, &stcb->sigpendingq);
         }
       else
         {
diff --git a/sched/sig_suspend.c b/sched/sig_suspend.c
index 92771578fb964dcf638eeb456e9a3f50f437431b..7f7acfce2935185b998d7139639c96ae69df038e 100644
--- a/sched/sig_suspend.c
+++ b/sched/sig_suspend.c
@@ -111,12 +111,12 @@
 
 int sigsuspend(const sigset_t *set)
 {
-  _TCB       *rtcb = (_TCB*)g_readytorun.head;
-  sigset_t    intersection;
-  sigset_t    saved_sigprocmask;
-  sigpendq_t *sigpend;
-  irqstate_t  saved_state;
-  int         unblocksigno;
+  FAR _TCB       *rtcb = (FAR _TCB*)g_readytorun.head;
+  sigset_t        intersection;
+  sigset_t        saved_sigprocmask;
+  FAR sigpendq_t *sigpend;
+  irqstate_t      saved_state;
+  int             unblocksigno;
 
   /* Several operations must be performed below:  We must determine if any
    * signal is pending and, if not, wait for the signal.  Since signals can
diff --git a/sched/sig_timedwait.c b/sched/sig_timedwait.c
index bba138fa7c0601ce3249629954224b2d810894db..eb3151dfa6c3b45d5ea06997700524a03329f0a8 100644
--- a/sched/sig_timedwait.c
+++ b/sched/sig_timedwait.c
@@ -88,8 +88,8 @@ static void sig_timeout(int argc, uint32 itcb, ...)
 
   union
     {
-      _TCB  *wtcb;
-      uint32 itcb;
+      FAR _TCB *wtcb;
+      uint32    itcb;
     } u;
 
    u.itcb = itcb;
@@ -160,13 +160,13 @@ static void sig_timeout(int argc, uint32 itcb, ...)
 int sigtimedwait(const sigset_t *set, struct siginfo *info,
                  const struct timespec *timeout)
 {
-  _TCB          *rtcb = (_TCB*)g_readytorun.head;
-  sigset_t       intersection;
-  sigpendq_t    *sigpend;
-  WDOG_ID        wdog;
-  irqstate_t     saved_state;
-  sint32         waitticks;
-  int            ret = ERROR;
+  FAR _TCB       *rtcb = (FAR _TCB*)g_readytorun.head;
+  sigset_t        intersection;
+  FAR sigpendq_t *sigpend;
+  WDOG_ID         wdog;
+  irqstate_t      saved_state;
+  sint32          waitticks;
+  int             ret = ERROR;
 
   sched_lock();  /* Not necessary */
 
diff --git a/sched/sig_unmaskpendingsignal.c b/sched/sig_unmaskpendingsignal.c
index c27ad126684bfcbdbd261b8b2803c4d3b50a6a88..77892dfc98e8a4bc01503da1c63b6abf55d2d3e9 100644
--- a/sched/sig_unmaskpendingsignal.c
+++ b/sched/sig_unmaskpendingsignal.c
@@ -78,10 +78,10 @@
 
 void sig_unmaskpendingsignal(void)
 {
-   _TCB       *rtcb = (_TCB*)g_readytorun.head;
-   sigset_t    unmaskedset;
-   sigpendq_t *pendingsig;
-   int         signo;
+   FAR _TCB       *rtcb = (FAR _TCB*)g_readytorun.head;
+   sigset_t        unmaskedset;
+   FAR sigpendq_t *pendingsig;
+   int             signo;
 
    /* Prohibit any context switches until we are done with this.
     * We may still be performing signal operations from interrupt
@@ -133,3 +133,4 @@ void sig_unmaskpendingsignal(void)
 
   sched_unlock();
 }
+
diff --git a/sched/task_create.c b/sched/task_create.c
index 79f487a11ec203f3f5c7a13c5bbbdd84b33a5f55..fe449b85fb01c9a35af57461620801539cf192a7 100644
--- a/sched/task_create.c
+++ b/sched/task_create.c
@@ -67,7 +67,7 @@
  ************************************************************/
 
 static void     task_start(void);
-static STATUS   task_assignpid(_TCB* tcb);
+static STATUS   task_assignpid(FAR _TCB* tcb);
 
 /************************************************************
  * Private Functions
@@ -92,7 +92,7 @@ static STATUS   task_assignpid(_TCB* tcb);
 
 static void task_start(void)
 {
-  _TCB *tcb = (_TCB*)g_readytorun.head;
+  FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head;
   int argc;
 
   /* Count how many non-null arguments we are passing */
@@ -127,7 +127,7 @@ static void task_start(void)
  *
  ************************************************************/
 
-static STATUS task_assignpid(_TCB *tcb)
+static STATUS task_assignpid(FAR _TCB *tcb)
 {
   pid_t next_pid;
   int   hash_ndx;
@@ -220,9 +220,10 @@ static STATUS task_assignpid(_TCB *tcb)
  *
  ************************************************************/
 
-STATUS _task_init(_TCB *tcb, char *name, int priority,
+STATUS _task_init(FAR _TCB *tcb, const char *name, int priority,
                   start_t start, main_t main, boolean pthread,
-                  char *arg1, char *arg2, char *arg3, char *arg4)
+                  FAR char *arg1, FAR char *arg2,
+                  FAR char *arg3, FAR char *arg4)
 {
   STATUS ret;
 
@@ -317,7 +318,7 @@ STATUS _task_init(_TCB *tcb, char *name, int priority,
       /* Add the task to the inactive task list */
 
       sched_lock();
-      dq_addfirst((dq_entry_t*)tcb, &g_inactivetasks);
+      dq_addfirst((FAR dq_entry_t*)tcb, &g_inactivetasks);
       tcb->task_state = TSTATE_TASK_INACTIVE;
       sched_unlock();
     }
@@ -348,9 +349,10 @@ STATUS _task_init(_TCB *tcb, char *name, int priority,
  *
  ************************************************************/
 
-STATUS task_init(_TCB *tcb, char *name, int priority,
-                 uint32 *stack, uint32 stack_size, main_t entry,
-                 char *arg1, char *arg2, char *arg3, char *arg4)
+STATUS task_init(FAR _TCB *tcb, const char *name, int priority,
+                 FAR uint32 *stack, uint32 stack_size, main_t entry,
+                 FAR char *arg1, FAR char *arg2,
+                 FAR char *arg3, FAR char *arg4)
 {
   up_use_stack(tcb, stack, stack_size);
   return _task_init(tcb, name, priority, task_start, entry,
@@ -374,7 +376,7 @@ STATUS task_init(_TCB *tcb, char *name, int priority,
  *
  ************************************************************/
 
-STATUS task_activate(_TCB *tcb)
+STATUS task_activate(FAR _TCB *tcb)
 {
 #ifdef CONFIG_SCHED_INSTRUMENTATION
   irqstate_t flags = irqsave();
@@ -433,17 +435,18 @@ STATUS task_activate(_TCB *tcb)
  *
  ************************************************************/
 
-int task_create(char *name, int priority,
+int task_create(const char *name, int priority,
                 int stack_size, main_t entry,
-                char *arg1, char *arg2, char *arg3, char *arg4)
+                FAR char *arg1, FAR char *arg2,
+                FAR char *arg3, FAR char *arg4)
 {
-  _TCB *tcb;
+  FAR _TCB *tcb;
   STATUS status;
   pid_t pid;
 
   /* Allocate a TCB for the new task. */
 
-  tcb = (_TCB*)kzmalloc(sizeof(_TCB));
+  tcb = (FAR _TCB*)kzmalloc(sizeof(_TCB));
   if (!tcb)
     {
       *get_errno_ptr() = ENOMEM;
@@ -486,7 +489,7 @@ int task_create(char *name, int priority,
    status = task_activate(tcb);
    if (status != OK)
     {
-      dq_rem((dq_entry_t*)tcb, &g_inactivetasks);
+      dq_rem((FAR dq_entry_t*)tcb, &g_inactivetasks);
       sched_releasetcb(tcb);
       return ERROR;
     }
diff --git a/sched/task_delete.c b/sched/task_delete.c
index ed169217d61017e6b4b8564a3ee74e5c69193b34..47d9a868f89b0b39fd6249af59b9848749a63dda 100644
--- a/sched/task_delete.c
+++ b/sched/task_delete.c
@@ -95,14 +95,14 @@
 
 STATUS task_delete(pid_t pid)
 {
-  _TCB      *rtcb;
-  _TCB      *dtcb;
+  FAR _TCB  *rtcb;
+  FAR _TCB  *dtcb;
   irqstate_t saved_state;
   STATUS     ret = ERROR;
 
    /* Check if the task to delete is the calling task */
 
-   rtcb = (_TCB*)g_readytorun.head;
+   rtcb = (FAR _TCB*)g_readytorun.head;
    if (pid == 0 || pid == rtcb->pid)
      {
        /* If it is, then what we really wanted to do was exit.
@@ -146,7 +146,7 @@ STATUS task_delete(pid_t pid)
 
   /* Remove the task from the OS's tasks lists. */
 
-  dq_rem((dq_entry_t*)dtcb, g_tasklisttable[dtcb->task_state].list);
+  dq_rem((FAR dq_entry_t*)dtcb, g_tasklisttable[dtcb->task_state].list);
   dtcb->task_state = TSTATE_TASK_INVALID;
   irqrestore(saved_state);
 
@@ -163,3 +163,4 @@ STATUS task_delete(pid_t pid)
   sched_releasetcb(dtcb);
   return ret;
 }
+
diff --git a/sched/task_restart.c b/sched/task_restart.c
index 60478c25811e6b075b73e7fab75fe1580e401afc..eb6ef8d722b50c7c897951ef07a045006bc27883 100644
--- a/sched/task_restart.c
+++ b/sched/task_restart.c
@@ -99,8 +99,8 @@
 
 STATUS task_restart(pid_t pid)
 {
-  _TCB      *rtcb;
-  _TCB      *tcb;
+  FAR _TCB  *rtcb;
+  FAR _TCB  *tcb;
   STATUS     status;
   irqstate_t state;
 
@@ -112,7 +112,7 @@ STATUS task_restart(pid_t pid)
 
    /* Check if the task to restart is the calling task */
 
-   rtcb = (_TCB*)g_readytorun.head;
+   rtcb = (FAR _TCB*)g_readytorun.head;
    if ((pid == 0) || (pid == rtcb->pid))
      {
        /* Not implemented */
@@ -139,7 +139,7 @@ STATUS task_restart(pid_t pid)
         */
 
        state = irqsave();
-       dq_rem((dq_entry_t*)tcb, g_tasklisttable[tcb->task_state].list);
+       dq_rem((FAR dq_entry_t*)tcb, g_tasklisttable[tcb->task_state].list);
        tcb->task_state = TSTATE_TASK_INVALID;
        irqrestore(state);
 
@@ -159,7 +159,7 @@ STATUS task_restart(pid_t pid)
 
        /* Add the task to the inactive task list */
 
-       dq_addfirst((dq_entry_t*)tcb, &g_inactivetasks);
+       dq_addfirst((FAR dq_entry_t*)tcb, &g_inactivetasks);
        tcb->task_state = TSTATE_TASK_INACTIVE;
 
        /* Activate the task */
@@ -167,7 +167,7 @@ STATUS task_restart(pid_t pid)
        status = task_activate(tcb);
        if (status != OK)
          {
-           dq_rem((dq_entry_t*)tcb, &g_inactivetasks);
+           dq_rem((FAR dq_entry_t*)tcb, &g_inactivetasks);
            sched_releasetcb(tcb);
            return ERROR;
          }
diff --git a/sched/wd_cancel.c b/sched/wd_cancel.c
index c0181e43becffb531c498662fb334ce1c8f21513..2872ce052171b0e0b99c7540afa4d0dc98741548 100644
--- a/sched/wd_cancel.c
+++ b/sched/wd_cancel.c
@@ -135,7 +135,7 @@ STATUS wd_cancel (WDOG_ID wdid)
           /* Now, remove the watchdog from the timer queue */
 
           if (prev)
-            (void)sq_remafter((sq_entry_t*)prev, &g_wdactivelist);
+            (void)sq_remafter((FAR sq_entry_t*)prev, &g_wdactivelist);
           else
             (void)sq_remfirst(&g_wdactivelist);
           wdid->next = NULL;
diff --git a/sched/wd_delete.c b/sched/wd_delete.c
index 96168ec2c2cfbe1afb2d2245edb51d8d0e138fab..7e2a4328e0dc4c89fe4dd0d5bbcee0e8d51ebfe9 100644
--- a/sched/wd_delete.c
+++ b/sched/wd_delete.c
@@ -88,7 +88,7 @@
  *
  ************************************************************/
 
-STATUS wd_delete (WDOG_ID wdId)
+STATUS wd_delete(WDOG_ID wdId)
 {
   irqstate_t saved_state;
 
@@ -99,7 +99,7 @@ STATUS wd_delete (WDOG_ID wdId)
 
   /* Put the watchdog back on the free list */
 
-  sq_addlast((sq_entry_t*)wdId, &g_wdfreelist);
+  sq_addlast((FAR sq_entry_t*)wdId, &g_wdfreelist);
   irqrestore(saved_state);
 
   /* Return success */
diff --git a/sched/wd_initialize.c b/sched/wd_initialize.c
index 5d979bb3dfec1f168a8a5b9e57e0312b809ce08b..a1d943079aedbc270f9daedd19dbc7f80e1b1f50 100644
--- a/sched/wd_initialize.c
+++ b/sched/wd_initialize.c
@@ -67,7 +67,7 @@ sq_queue_t g_wdfreelist;
  * item.
  */
 
-wdog_t *g_wdpool;
+FAR wdog_t *g_wdpool;
 
 /* The g_wdactivelist data structure is a singly linked list
  * ordered by watchdog expiration time. When watchdog timers
@@ -118,15 +118,15 @@ void wd_initialize(void)
    * configured number of watchdogs.
    */
 
-  g_wdpool = (wdog_t*)kmalloc(sizeof(wdog_t) * CONFIG_PREALLOC_WDOGS);
+  g_wdpool = (FAR wdog_t*)kmalloc(sizeof(wdog_t) * CONFIG_PREALLOC_WDOGS);
   if (g_wdpool)
     {
-      wdog_t *wdog = g_wdpool;
+      FAR wdog_t *wdog = g_wdpool;
       int i;
 
       for (i = 0; i < CONFIG_PREALLOC_WDOGS; i++)
         {
-          sq_addlast((sq_entry_t*)wdog++, &g_wdfreelist);
+          sq_addlast((FAR sq_entry_t*)wdog++, &g_wdfreelist);
         }
     }
 
diff --git a/sched/wd_internal.h b/sched/wd_internal.h
index 7794d8c12a58eaf1d8696c6a4508051e3a0eed9a..26ee264adcedf9efe71bccc8cf06dff752b31b6e 100644
--- a/sched/wd_internal.h
+++ b/sched/wd_internal.h
@@ -88,7 +88,7 @@ extern sq_queue_t g_wdfreelist;
  * item.
  */
 
-extern wdog_t *g_wdpool;
+extern FAR wdog_t *g_wdpool;
 
 /* The g_wdactivelist data structure is a singly linked list
  * ordered by watchdog expiration time. When watchdog timers
diff --git a/sched/wd_start.c b/sched/wd_start.c
index b3534593d2729cbc8a87da2fd70fd7798029616b..a0fb469dea298bc4068022e3e95bacab6e9cf251 100644
--- a/sched/wd_start.c
+++ b/sched/wd_start.c
@@ -185,7 +185,7 @@ STATUS wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry,
 
   if (g_wdactivelist.head == NULL)
     {
-      sq_addlast((sq_entry_t*)wdog,&g_wdactivelist);
+      sq_addlast((FAR sq_entry_t*)wdog,&g_wdactivelist);
     }
 
   /* There are other active watchdogs in the timer queue */
@@ -228,11 +228,11 @@ STATUS wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry,
 
           if (curr == (wdog_t*)g_wdactivelist.head)
             {
-              sq_addfirst((sq_entry_t*)wdog, &g_wdactivelist);
+              sq_addfirst((FAR sq_entry_t*)wdog, &g_wdactivelist);
             }
           else
             {
-              sq_addafter((sq_entry_t*)prev, (sq_entry_t*)wdog,
+              sq_addafter((FAR sq_entry_t*)prev, (FAR sq_entry_t*)wdog,
                           &g_wdactivelist);
             }
         }
@@ -247,13 +247,13 @@ STATUS wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry,
           delay -= now;
           if (!curr->next)
             {
-              sq_addlast((sq_entry_t*)wdog, &g_wdactivelist);
+              sq_addlast((FAR sq_entry_t*)wdog, &g_wdactivelist);
             }
           else
             {
               next = curr->next;
               next->lag -= delay;
-              sq_addafter((sq_entry_t*)curr, (sq_entry_t*)wdog,
+              sq_addafter((FAR sq_entry_t*)curr, (FAR sq_entry_t*)wdog,
                           &g_wdactivelist);
             }
         }
diff --git a/tools/mkdeps.sh b/tools/mkdeps.sh
index 54ffbb1ee8d61ddd50361c960e6ac52d2dfc467e..c2b81ec2e056127271fe0bb291fc5eb2cc0610a2 100755
--- a/tools/mkdeps.sh
+++ b/tools/mkdeps.sh
@@ -53,7 +53,7 @@ for i in $* ; do
     cflags=$args
     args=
     ;;
-  --debug )
+  --dep-debug )
     set -x
     ;;
   *)
@@ -75,6 +75,6 @@ fi
 
 for file in $files ; do
   $cc -M $cflags $file || \
-    { echo "$cc -M $cflags $file FAILED" ; exit 3 ; }
+    { echo "# $cc -M $cflags $file FAILED" ; exit 3 ; }
 done