unix编程 之 操作目录函数

#include "ourhdr.h"
#include "base.h"
#include <sys/types.h>
#include <dirent.h>

int32 main(int32 argc , char* argv[])
{
    int32 iRet = 0 ;
    DIR *dp ;
    struct dirent *dirp ;
    if(argc != 2)
    {
        //err_quit("err argument");
        printf("eror argument\n");
        exit(-1) ;
    }
    if((dp = opendir(argv[1])) == NULL)
    {
        //err_sys("can't open %s",argv[1]);
        printf("can't open %s\n",argv[1]);
        exit(-1);
    }
    while( (dirp = readdir(dp)) != NULL)
    {
        printf("%s\n",dirp->d_name);
    }
    closedir(dp);
   
    return iRet ;  
}

###############################################
#               Makefile                      #
###############################################
CC=g++
CFLAGS=-Wall -g -fPIC
#lib path
LIB_PATH=/home/huangxw/ob_rel/lib
#include path
CFLAGS+=-I /home/huangxw/work/project/include
#target
TARGET=test
#macro definition
CFLAGS+=-D USER_DEF
#source files
SOURCES=$(shell find ./ -name \*.cpp)
#include path
INCLUDE_PATH=/home/huangxw/work/project/include
#
$(TARGET):$(SOURCES)
$(CC) $?  -I $(INCLUDE_PATH) -L $(LIB_PATH) -lc -o $@

###############################################
clean:
rm -rf $(TARGET)
rm -rf core

你可能感兴趣的:(编程,unix,null,Path,include,makefile)