[lingyun@localhost getcwd]$ cat getcwd.c
/*********************************************************************************

 *      Copyright:  (C) 2013 fulinux<fulinux@sina.com> 

 *                  All rights reserved.

 *

 *       Filename:  getcwd.c

 *    Description:  This file 

 *                 

 *        Version:  1.0.0(08/06/2013~)

 *         Author:  fulinux <fulinux@sina.com>

 *      ChangeLog:  1, Release initial version on "08/06/2013 03:56:30 PM"

 *                 

 ********************************************************************************/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

int main(void)

{

    char *ptr;

    int size = 50;

    if(chdir("/usr/tmp/yum-lingyun-sYjnfB") < 0)

    {

        perror("chdir");

        exit(1);

    }

    ptr = malloc(size);

if(getcwd(ptr, size) == NULL)

    {

        perror("getcwd");

        exit(1);

    }

printf("cwd = %s\n", ptr);

    exit(0);

}

[lingyun@localhost getcwd]$ ll /usr/

total 224

dr-xr-xr-x.   2 root root 69632 Apr 29 03:32 bin

drwxr-xr-x.   2 root root  4096 Sep 23  2011 etc

drwxr-xr-x.   2 root root  4096 Sep 23  2011 games

drwxr-xr-x.  39 root root  4096 Apr 15 15:44 include

dr-xr-xr-x.  29 root root  4096 Apr 22 03:18 lib

dr-xr-xr-x. 132 root root 86016 Apr 29 03:32 lib64

drwxr-xr-x.  30 root root 12288 Apr 29 03:32 libexec

drwxr-xr-x.  15 root root  4096 Jun  5 19:57 local

drwxr-xr-x    3 root root  4096 Apr 21 20:38 man

dr-xr-xr-x.   2 root root 12288 Jul 30 03:42 sbin

drwxr-xr-x. 265 root root 12288 Jun  9 09:34 share

drwxr-xr-x.   4 root root  4096 Jul  6  2012 src

lrwxrwxrwx.   1 root root    10 Jul  6  2012 tmp -> ../var/tmp

[lingyun@localhost getcwd]$ ls /usr/tmp/yum-lingyun-sYjnfB/

[lingyun@localhost getcwd]$ gcc getcwd.c 

[lingyun@localhost getcwd]$ ./a.out 

cwd = /var/tmp/yum-lingyun-sYjnfB

[lingyun@localhost getcwd]$

linux之getcwd函数解析的更多相关文章

  1. Linux exec族函数解析

    背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...

  2. linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c  /********************************************************* ...

  3. linux之access函数解析

    [lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c  /******** ...

  4. linux之ioctl函数解析

    [lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c  /*********** ...

  5. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  6. linux之utime函数解析

    [lingyun@localhost utime]$ ls hello  utime.c  world [lingyun@localhost utime]$ cat utime.c  /******* ...

  7. linux之chdir函数解析

    [lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c  /********************* ...

  8. linux之stat函数解析

    [lingyun@localhost stat_1]$ vim stat.c  + stat.c                                                     ...

  9. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

随机推荐

  1. PHP常用魔术方法(__toString魔术方法)

    <?php //文件名:index.php define('a',__DIR__); include '/IMooc/Loader.php'; spl_autoload_register('\\ ...

  2. python下载多个文件

    # -*- coding: utf-8 -*-__author__ = 'Administrator'import urllib2,urllib,os,redef Url1(url):#多个文件    ...

  3. 高效求幂取余 算法,复杂度 log(n)

    做TopCoder SRM 576 D2 L3 题目时,程序有个地方需要对一个数大量求幂并取余,导致程序运行时间很长,看了Editoral之后,发现一个超级高效的求幂并取余的算法,之前做System ...

  4. work staff

    培训一周,很抓狂.不是抓狂培训本身,是自己听不懂,培训还是有用的. 上周四接到一个task,关于checklist.因为组里没有人用过,所以遇到一些问题,本来不应该是一个复杂的工作,但是我需要一个一个 ...

  5. 使用WinAPI全局热键注册和全局模拟按键

    一.全局热键注册 1.先引用DLL [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI publ ...

  6. EF执行存储过程(带输出参数)

    1.不含动态sql.带输出参数存储过程调用实例 1.存储过程代码:   2.EF自动生成代码(包括对应ObjectResult的实体模型): 3.调用存储过程代码实例: 总结: ObjectParam ...

  7. Android打开外部DB文件

    DB文件要放在Assets文件夹下,封装一个工具类,如下: package com.XX.DB; import java.io.File; import java.io.FileOutputStrea ...

  8. linux删除ORACLE【weber出品必属精品】

    关闭数据库 sqlplus / as sysdba shutdown abort 清除oracle软件 su - oracle cd $ORACLE_BASE rm -rf * rm -rf /etc ...

  9. MySql函数应用

    -- 当前时间 now(); -- 查询结果串联(逗号) select group_concat(col_name) from table_name;

  10. mysql对GIS空间数据的支持,包括创建空间索引

    CREATE TABLE tb_geo( id INT PRIMARY KEY AUTO_INCREMENT, NAME ) NOT NULL, pnt POINT NOT NULL, SPATIAL ...