summaryrefslogtreecommitdiff
path: root/nuttx/lib/lib_getcwd.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-23 15:16:10 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-23 15:16:10 +0000
commit872cf9f99f8b6e2a64781c0c6bc8aee6e35f5cb7 (patch)
tree27c66a47011dea19170420a26a954591f02e8c53 /nuttx/lib/lib_getcwd.c
parentb588aaaa96a83162f43a4ea409be382a01aa3812 (diff)
downloadpx4-nuttx-872cf9f99f8b6e2a64781c0c6bc8aee6e35f5cb7.tar.gz
px4-nuttx-872cf9f99f8b6e2a64781c0c6bc8aee6e35f5cb7.tar.bz2
px4-nuttx-872cf9f99f8b6e2a64781c0c6bc8aee6e35f5cb7.zip
Added ch and pwd to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@841 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_getcwd.c')
-rw-r--r--nuttx/lib/lib_getcwd.c79
1 files changed, 35 insertions, 44 deletions
diff --git a/nuttx/lib/lib_getcwd.c b/nuttx/lib/lib_getcwd.c
index a0db05c09..20f7cef48 100644
--- a/nuttx/lib/lib_getcwd.c
+++ b/nuttx/lib/lib_getcwd.c
@@ -40,12 +40,15 @@
#include <nuttx/config.h>
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "lib_internal.h"
+#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)
+
/****************************************************************************
* Definitions
****************************************************************************/
@@ -90,50 +93,38 @@
*
****************************************************************************/
-#if CONFIG_NFILE_DESCRIPTORS > 0
FAR char *getcwd(FAR char *buf, size_t size)
{
- const char *ptr;
- int err;
-
- /* Verify input parameters */
-
- if (!buf || !size)
- {
- err = EINVAL;
- goto errout;
- }
-
- /* If no working directory is defined, then default to the home directory */
-
- cwd_semtake();
- if (g_cwd)
- {
- ptr = g_cwd;
- }
- else
- {
- ptr = CONFIG_LIB_HOMEDIR;
- }
-
- /* Verify that the cwd will fit into the user-provided buffer */
-
- if (strlen(ptr) + 1 > size)
- {
- err = ERANGE;
- goto errout_with_sem;
- }
-
- /* Copy the cwd to the user buffer */
-
- strcpy(buf, ptr);
- cwd_semgive();
- return buf;
-
-errout_with_sem:
- cwd_semgive();
-errout:
- errno = err;
- return NULL;
+ char *pwd;
+
+ /* Verify input parameters */
+
+ if (!buf || !size)
+ {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ /* If no working directory is defined, then default to the home directory */
+
+ pwd = getenv("PWD");
+ if (!pwd)
+ {
+ pwd = CONFIG_LIB_HOMEDIR;
+ }
+
+ /* Verify that the cwd will fit into the user-provided buffer */
+
+ if (strlen(pwd) + 1 > size)
+ {
+ errno = ERANGE;
+ return NULL;
+ }
+
+ /* Copy the cwd to the user buffer */
+
+ strcpy(buf, pwd);
+ sched_unlock();
+ return buf;
}
-#endif /* CONFIG_NFILE_DESCRIPTORS */
+#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_DISABLE_ENVIRON */