2015年1月22日 星期四

[C] Get environment variable


Embedded System
armeb-unknown-linux-uclibcgnueabi-gcc env.c
/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2014.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU General Public License as published by the   *
* Free Software Foundation, either version 3 or (at your option) any      *
* later version. This program is distributed without any warranty.  See   *
* the file COPYING.gpl-v3 for details.                                    *
\*************************************************************************/

#include<stdio.h>

extern char **environ;

int main(int argc, char *argv[])
{
        char **ep;
        for (ep = environ; *ep != NULL; ep++)
                puts(*ep);

        return 0;
}


Result:
USER=root
LD_LIBRARY_PATH=/gw/lib:/gw/usr/lib:/lib:/usr/lib:/lib:/usr/lib
OLDPWD=/tmp
HOME=/
usbhostaddr=
TERM=vt102
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin:/gw/sbin:/gw/bin:/gw/usr/sbin:/gw/
SHELL=/bin/sh
PWD=/tmp


Reference:
1. The Linux Programming Interface

0 意見:

張貼留言