busybox源码剖析(2)

pwd命令是列出当前的路径。

pwd_main(int argc, char **argv) 2 {*buf; 4 5buf = xgetcwd(buf);(buf != NULL) { 8 puts(buf); 9return EXIT_SUCCESS;10 }11return EXIT_FAILURE;12 }

通过xgetcwd函数将路径保存到buf中。

char *xgetcwd (char *cwd){ char *ret; unsigned path_max;errno = 0; path_max = (unsigned) PATH_MAX; path_max += (cwd==0)cwd = xmalloc (path_max);errno = 0; while ((ret = getcwd (cwd, path_max)) == NULL && errno == ERANGE) {path_max += PATH_INCR;cwd = xrealloc (cwd, path_max);errno = 0; }if (ret == NULL) {int save_errno = errno;free (cwd);errno = save_errno;perror_msg();return NULL; }return cwd;}

通过getcwd()得到当前路径。

这个命令的实现很简单。记录一下。

,美国服务器,网站空间,香港虚拟主机也有伤心的,既有令人兴奋的,也有令人灰心的,

busybox源码剖析(2)

相关文章:

你感兴趣的文章:

标签云: