当前位置: 首页>>代码示例>>C++>>正文


C++ closedir函数代码示例

本文整理汇总了C++中closedir函数的典型用法代码示例。如果您正苦于以下问题:C++ closedir函数的具体用法?C++ closedir怎么用?C++ closedir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了closedir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FindSaveGame

bool FindSaveGame(int nGame, char *psz, int cb, int *pc = NULL)
{
	if (pc != NULL)
		*pc = 0;

    // This is the prefix of the file being looked for

	char szCompare[PATH_MAX];
	sprintf(szCompare, "htsave%d_", nGame);
	int cchCompare = strlen(szCompare);

    // This is the special save game that is only used
    // when the game exits and reloads right away

	char szReinitializeSave[20];
	sprintf(szReinitializeSave, "htsave%d_", knGameReinitializeSave);
	int cchReinitializeSave = strlen(szReinitializeSave);

    // Enum files in this directory

	char szFileSpec[PATH_MAX];
	PrependSavesDirectory("", szFileSpec);
    DIR *pdir = opendir(szFileSpec);
    if (pdir == NULL) {
        return false;
    }

    int c = 0;
    dirent *pdent;
    while ((pdent = readdir(pdir)) != NULL) {
        // Only consider save games, because if the desired save game is
        // not found, we need to count "slots".

        if (strncmp("htsave", pdent->d_name, 6) != 0) {
            continue;
        }

        // Save game found?

        if (strncmp(szCompare, pdent->d_name, cchCompare) == 0) {
			if (psz != NULL)
				strncpyz(psz, pdent->d_name, cb);
			closedir(pdir);
			return true;
		}

        // Count save games but don't count the temporary "Reinitialize"
        // saved game

		if (strncmp(szReinitializeSave, pdent->d_name,
                cchReinitializeSave) == 0) {
			continue;
        }

        // Count this save game as a slot

		c++;
    }
    closedir(pdir);

    // Didn't find the saved game, but did count the number of occupied slots

	if (pc != NULL)
		*pc = c;
	return false;
}
开发者ID:Ahmar,项目名称:hostile-takeover,代码行数:66,代码来源:savegame.cpp

示例2: connection_handler

void* connection_handler(void* number)
{
	int thread_num = *(int*)number;
	int read_size;
	char client_message[2000];

	getcwd(current_dir[N], 5000);

	printf("[%d] created.\n", thread_num);

	while(!is_working[thread_num]);

	while( (read_size = recv(client_sockets[thread_num] , client_message , 2000 , 0)) > 0 )
	{
		char* command = strtok(client_message, " ");
		printf("[%d] Command: [%s]\n", thread_num, command);
		if (strcmp("LIST", command) == 0)
		{
			char response[10000];

			DIR           *d;
			struct dirent *dir;
			d = opendir(current_dir[thread_num]);
			if (d)
			{
				strcpy(response, "");
				while ((dir = readdir(d)) != NULL)
				{
					
					strcat(response, dir->d_name);
					strcat(response, "\n");
				}

				closedir(d);
			}

			write(client_sockets[thread_num] , response , strlen(response));
		}
		else if (strcmp("CWD", command) == 0)
		{
			char* path = strtok(NULL, " ");
			printf("[%d] Path: [%s]\n", thread_num, path);			
			

			char response[1000];

			struct stat s;
			int err = stat(path, &s);

			if (err != -1 && S_ISDIR(s.st_mode)) // is a dir
			{
				strcpy(current_dir[thread_num], path);
				sprintf(response, "Ok, current_path = %s\n", current_dir[thread_num]);
			}
			else
			{
				sprintf(response, "Wrong path, sorry.\n");
			}

			
			write(client_sockets[thread_num] , response , strlen(response));
		}

		memset(client_message,0,sizeof(client_message));

		
	}

	close(client_sockets[thread_num]);

	printf("[%d] Connection closed.\n", thread_num);

	pthread_create(&tid[thread_num] , NULL , connection_handler , (void*) &thread_num);
	is_working[thread_num] = 0;

	printf("[%d] destroyed.\n", thread_num);
}
开发者ID:eusmirnov51,项目名称:OS,代码行数:77,代码来源:server.c

示例3: while

void MainWindow::on_object_id_textChanged(const QString &arg1)
{
    // show all faces allready taged with the id of the object_id field
    QString id = ui->object_id->text();

    std::vector<QPixmap> listCrops;

    QString dir_name = Manager::exemplar()->selectedDirectory;//"/home/daniel/BaoDataBase/myDataBase";
    // collect all FaceObjects and imagees with the given id
    DIR *dir;
    struct dirent *ent;
    struct stat info;
    const char *c_str2 = dir_name.toLocal8Bit().data();
    if ((dir = opendir (c_str2)) != NULL) {
      /* print all the files and directories within directory */
      while ((ent = readdir (dir)) != NULL) {
          stat(ent->d_name, &info);
          //if(!S_ISDIR (info.st_mode)) {
            //qDebug() << ent->d_name;
            std::vector<FaceObject> list = readObjectFile(dir_name.toStdString() + "/.metaface/" + ent->d_name + ".txt");
            if(list.size() > 0) {
                for(std::vector<FaceObject>::iterator it = list.begin(); it != list.end(); ++it) {
                    FaceObject fo = *it;
                    if(fo.objectID == id.toStdString()) {
                        qDebug() << "found a face in:" << ent->d_name;
                        QPixmap * img = new QPixmap();
                        QString fileName = QString::fromStdString(ent->d_name);
                        img->load(dir_name + "/" + fileName);
                        //QPixmap::copy(int x, int y, int width, int height )
                        QPixmap imgCroped = img->copy(fo.x, fo.y, fo.width, fo.height);
                        qDebug() << "image crop x:" << fo.x << "y:" << fo.y << "width" << fo.width << "height:" << fo.height;
                        listCrops.push_back(imgCroped);
                    }

                }
            }
      }
      closedir (dir);
    }

    // check how many croped faces are stored in the list
    qDebug() << "there are " << listCrops.size() << " store in the vector";



    //QString imgPath = "/home/daniel/facetag/datasettools2/datasettools80.png";
    //QImage *img = new QImage();
    //bool loaded = img->load(imgPath);
    //if (loaded)
    //{
        /*QTableWidgetItem *thumbnail = new QTableWidgetItem;
        thumbnail->setData(Qt::DecorationRole, QPixmap::fromImage(*img));

        //thumbnailsWidget->setColumnCount(3);
        //thumbnailsWidget->setRowCount(3);
        ui->tableIamges->setItem(0, 0, thumbnail);*/

        //w.setCentralWidget(thumbnailsWidget);
    //} else {
        //qDebug()<<"Image "<<imgPath<<" was not opened!";
   // }
        int row = 0;
        int column = 0;
        int cell = 0;
        for(std::vector<QPixmap>::iterator it = listCrops.begin(); it != listCrops.end(); ++it) {
            QPixmap pm = *it;
            pm = pm.scaledToHeight(80,Qt::SmoothTransformation);
            QTableWidgetItem *thumbnail = new QTableWidgetItem;
            thumbnail->setData(Qt::DecorationRole, pm);
            ui->tableIamges->setItem(column, row, thumbnail);
            if(column == 2) {
                row++;
                cell++;
                column = 0;
            } else {
                row++;
                cell++;
            }
        }

        int maxCells = ui->tableIamges->rowCount() * ui->tableIamges->columnCount();
        while(cell < 9) {
            QTableWidgetItem *thumbnail = new QTableWidgetItem;
            ui->tableIamges->setItem(column, row, thumbnail);
            if(column == 2) {
                row++;
                cell++;
                column = 0;
            } else {
                row++;
                cell++;
            }
        }
}
开发者ID:ExtremeModerate,项目名称:lr-facetags,代码行数:94,代码来源:mainwindow.cpp

示例4: malloc

csFILE *CS_fopen(const char *filename, const char *mode)
{
	extern char cs_DirsepC;
	struct stat statbuf;
	csFILE *result = NULL;
	char *fixed_filename = (char*) filename;

	/* If we are attempting to read from the file, and the file passed
	 * in does not exist, look for a different file in the same directory
	 * that has the same filename with a different case.
	 */

	if ( (*mode == *_STRM_TXTRD) && stat(filename,&statbuf) )
	{
		/* Make a copy of the filename passed in, and separate it into
		 * directory and path components.
		 */

		char *last_path_sep;

		fixed_filename = (char*) malloc(strlen(filename)+1);
		strcpy(fixed_filename,filename);
		last_path_sep = strrchr(fixed_filename,cs_DirsepC);
		if ( last_path_sep )
		{
			/* Unless the directory is the current directory, we'd
			 * better make sure that at least the directory exists!
			 */
			char *filename_part = last_path_sep + 1;
			*last_path_sep = '\0';
			if ( ! stat(fixed_filename,&statbuf) )
			{
				/* Search the contents of the directory for a file which
				 * matches the one passed in, allowing for different
				 * case.
				 */
#if 1
				DIR *directory = opendir(fixed_filename);
				if ( directory )
				{
					struct dirent *entry;
					while ( (entry = readdir(directory)) != 0 )
					{
						if ( ! CS_stricmp(entry->d_name,filename_part) )
						{
							 /* We have a match!  It should be safe to assume that
							  * their lengths are the same, so we'll just copy it
							  * in-place.
							  */
							strcpy(filename_part,entry->d_name);
							break;
						}
					}
					closedir(directory);
				}
#else
				struct dirent *name_list = NULL;
				int num_matches = scandir( fixed_filename, name_list, NULL, NULL);
				if (num_matches > 0)
				{
					int ii;
					for (ii=0;ii < num_matches;ii++ )
					{
						if (!CS_stricmp (name_list[ii].d_name,filename_part))
						{
							 /* We have a match!  It should be safe to assume that
							  * their lengths are the same, so we'll just copy it
							  * in-place.
							  */
							strcpy (filename_part,name_list[ii].d_name);
							break;
						}
					}
					free (name_list);
				}
#endif
				/* Replace the directory/path separator */
				*last_path_sep = cs_DirsepC;
			}
		}
	}
	result = (csFILE*) fopen(fixed_filename,mode);
	if ( filename != fixed_filename )
	{
		free(fixed_filename);
	}
	return result;
}
开发者ID:asir6,项目名称:Colt,代码行数:88,代码来源:CS_system.c

示例5: main

int main() {
	std::setlocale(LC_ALL, "de_DE.UTF-8"); // important for utf-8 multibyte chars
	const std::string path = "/home/typology/1/";
	const std::string path2 = "/home/typology/1sorted/";
	 struct dirent *entry;
	  DIR *dp;

	  dp = opendir(path.c_str());
	  if (dp == NULL) {
	    std::cout << "Path \"" << path << "\" does not exist or could not be read." << std::endl;
	    return 1;
	  }

	  std::string source;
	  std::string target;
	  float score;
	  std::vector<std::string> vSource;
	  std::vector<std::string> vTarget;
	  std::vector<float> vScore;
	  std::tuple<int,char> foo;
	  std::vector<std::tuple<std::string,std::string,float>>* vt = new std::vector<std::tuple<std::string,std::string,float>>();
	  std::vector<std::string> filenames;

	  while ((entry = readdir(dp))){
		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
			continue;
		}
		filenames.push_back(entry->d_name);
	  }
	  closedir(dp);
	  std::sort(filenames.begin(), filenames.end());
	  wchar_t lastChar;
	  wchar_t currentChar;
	  std::string lastfName;

	  mbrtowc(&lastChar, &filenames[0][0], MB_CUR_MAX, NULL); // Convert multibyte sequence (utf-8) to wide character
	  lastfName = filenames[0];
	  for(auto iter = filenames.begin(); iter != filenames.end(); ++iter) {
		  mbrtowc(&currentChar, &((*iter)[0]), 4, NULL);
		  		if(currentChar != lastChar) {
		  			std::sort(vt->begin(),vt->end(),&compareTwoRows);
		  			std::ofstream myfile ((path2 + lastfName).c_str() );
		  			if (myfile.is_open())
		  			{
		  				for (auto i : *vt){
		  					myfile << std::get<0>(i) << '\t' << std::get<1>(i) << '\t' << std::get<2>(i) << '\n';
		  				}
		  			  myfile.close();
		  			}
		  			vt->clear();
		  			lastChar = currentChar;
		  			lastfName = *iter;
		  		}
	    std::ifstream file((path + *iter).c_str());
	    std::cout << "reading file : " << path + *iter << std::endl;
	    for(std::string line; getline(file, line);) {
			std::istringstream ss(line);
			ss >> source >> target;
			ss.ignore(2);
			ss >> score;
			vt->push_back(std::make_tuple (source, target, score));
	    }

  		if(iter == filenames.end() - 1) {
  			std::sort(vt->begin(),vt->end(),&compareTwoRows);
  			std::ofstream myfile ((path2 + lastfName).c_str() );
  			if (myfile.is_open())
  			{
  				for (auto i : *vt){
  					myfile << std::get<0>(i) << '\t' << std::get<1>(i) << '\t' << std::get<2>(i) << '\n';
  				}
  			  myfile.close();
  			}
  		}
	  }
	  delete vt;
	  return 0;
}
开发者ID:chrip,项目名称:typology-bitmaps,代码行数:78,代码来源:GroupyByOrder.cpp

示例6: main

int main(){
    int i,line;
    char content[MAX_SCHEDULER][MAXLINE];
    int pipe_fd[2];
    FILE* fptr,*tmp_fptr;
    struct dirent *dirp;
    DIR* dp;
    pid_t pid;
    if((dp=opendir(dirname))==NULL)
        err_sys();
    while((dirp=readdir(dp))!=NULL)
        if(strcmp(dirp->d_name,".")==0 || strcmp(dirp->d_name,"..")==0)
            continue;
        else
            break;
    if(dirp==NULL)
        _Exit(0);
    if((tmp_fptr=fopen(tmp_filename,"w"))==NULL)
        err_sys();
    if(pipe(pipe_fd)<0)
        err_sys();
    if((pid=fork())<0){
        err_sys();
    }else if(pid>0){ //parent , read from pipe
        close(pipe_fd[1]);
        if((fptr=fdopen(pipe_fd[0],"r"))==NULL)
            err_sys();
        for(line=0;fgets(content[line],MAXLINE,fptr)>0;line++);
        if(fclose(fptr)==-1)
            err_sys();
        if(waitpid(pid,NULL,0)<0)
            err_sys();
    }else{ //child , write to pipe
        close(pipe_fd[0]);
        if(pipe_fd[1] != STDOUT_FILENO){
            if(dup2(pipe_fd[1],STDOUT_FILENO) != STDOUT_FILENO)
                err_sys();
            close(pipe_fd[1]);
        }
        if(execl("/usr/bin/crontab","crontab","-l",NULL)<0)
            err_sys();
    }
    deal_content(content,&line,dp,dirp);
    if(closedir(dp))
        err_sys();
    for(i=0;i<line;i++)
        fprintf(tmp_fptr,"%s",content[i]);
    if(fclose(tmp_fptr)==-1)
        err_sys();
    if((pid=fork())<0){
        err_sys();
    }else if(pid>0){ //parent
        if(waitpid(pid,NULL,0)<0)
            err_sys();
    }else{ //child
        if(execl("/usr/bin/crontab","crontab",tmp_filename,NULL)<0)
            err_sys();
    }
    if(unlink(tmp_filename)==-1)
        err_sys();
    return 0;
}
开发者ID:hkegbert,项目名称:ICS,代码行数:62,代码来源:core.c

示例7: opendir

/* lnstat_scan_dir - find and parse all available statistics files/fields */
struct lnstat_file *lnstat_scan_dir(const char *path, const int num_req_files,
				    const char **req_files)
{
	DIR *dir;
	struct lnstat_file *lnstat_files = NULL;
	struct dirent *de;

	if (!path)
		path = PROC_NET_STAT;

	dir = opendir(path);
	if (!dir) {
		struct lnstat_file *lf;
		/* Old kernel, before /proc/net/stat was introduced */
		fprintf(stderr, "Your kernel doesn't have lnstat support. ");

		/* we only support rtstat, not multiple files */
		if (num_req_files >= 2) {
			fputc('\n', stderr);
			return NULL;
		}

		/* we really only accept rt_cache */
		if (num_req_files && !name_in_array(num_req_files,
						    req_files, "rt_cache")) {
			fputc('\n', stderr);
			return NULL;
		}

		fprintf(stderr, "Fallback to old rtstat-only operation\n");

		lf = alloc_and_open("/proc/net", "rt_cache_stat");
		if (!lf)
			return NULL;
		lf->compat = 1;
		strncpy(lf->basename, "rt_cache", sizeof(lf->basename));

		/* FIXME: support for old files */
		if (lnstat_scan_compat_rtstat_fields(lf) < 0)
			return NULL;

		lf->next = lnstat_files;
		lnstat_files = lf;
		return lnstat_files;
	}

	while ((de = readdir(dir))) {
		struct lnstat_file *lf;

		if (de->d_type != DT_REG)
			continue;

		if (num_req_files && !name_in_array(num_req_files,
						    req_files, de->d_name))
			continue;

		lf = alloc_and_open(path, de->d_name);
		if (!lf)
			return NULL;

		/* fill in field structure */
		if (lnstat_scan_fields(lf) < 0)
			return NULL;

		/* prepend to global list */
		lf->next = lnstat_files;
		lnstat_files = lf;
	}
	closedir(dir);

	return lnstat_files;
}
开发者ID:247a,项目名称:lenovo_b6000-8000_kernel_source,代码行数:73,代码来源:lnstat_util.c

示例8: closedirectory

static void
closedirectory(directory_type *dir)
{
closedir(dir);
}
开发者ID:LeoNelson,项目名称:hypermail,代码行数:5,代码来源:pcregrep.c

示例9: qemu_find_file

static void *mpc8544_load_device_tree(target_phys_addr_t addr,
                                     uint32_t ramsize,
                                     target_phys_addr_t initrd_base,
                                     target_phys_addr_t initrd_size,
                                     const char *kernel_cmdline)
{
    void *fdt = NULL;
#ifdef CONFIG_FDT
    uint32_t mem_reg_property[] = {0, ramsize};
    char *filename;
    int fdt_size;
    int ret;

    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
    if (!filename) {
        goto out;
    }
    fdt = load_device_tree(filename, &fdt_size);
    qemu_free(filename);
    if (fdt == NULL) {
        goto out;
    }

    /* Manipulate device tree in memory. */
    ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
                               sizeof(mem_reg_property));
    if (ret < 0)
        fprintf(stderr, "couldn't set /memory/reg\n");

    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
                                    initrd_base);
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");

    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
                                    (initrd_base + initrd_size));
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");

    ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
                                      kernel_cmdline);
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/bootargs\n");

    if (kvm_enabled()) {
        struct dirent *dirp;
        DIR *dp;
        char buf[128];

        if ((dp = opendir("/proc/device-tree/cpus/")) == NULL) {
            printf("Can't open directory /proc/device-tree/cpus/\n");
            goto out;
        }

        buf[0] = '\0';
        while ((dirp = readdir(dp)) != NULL) {
            if (strncmp(dirp->d_name, "PowerPC", 7) == 0) {
                snprintf(buf, 128, "/cpus/%s", dirp->d_name);
                break;
            }
        }
        closedir(dp);
        if (buf[0] == '\0') {
            printf("Unknow host!\n");
            goto out;
        }

        mpc8544_copy_soc_cell(fdt, buf, "clock-frequency");
        mpc8544_copy_soc_cell(fdt, buf, "timebase-frequency");
    }

    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);

out:
#endif

    return fdt;
}
开发者ID:mithleshvrts,项目名称:qemu-kvm-rhel6,代码行数:78,代码来源:ppce500_mpc8544ds.c

示例10: while

/**
    Searches the supplied root directory for the extension provided. Can recursively search downward through the directory tree
    to get all files. It will then return a vector of file paths that fulfill the search requirements.
    USAGE:
    extension should be preceeded by the '.' character to denote it as an extension, if it is not then it will return all files
    and folder names that contain the extension string.
    root_path can point to any folder relative to the execution directory.
        Searching from the execution directory -- Supply "." as the root_path
        Searching from the parent directory of the execution directory -- Supply ".." as the root_path
        Searching child directories within the execution directory -- Supply "<directory path>" or "./<directory path>", both
            will provide correct results.
    recursive_search will:
        if true, continue searching all child directories from the supplied root_path
        if false, search only the supplied root_path, and stop when the directory contents have been worked through.
*/
std::vector<std::string> file_finder::get_files_from_path(std::string extension, std::string root_path, bool recursive_search)
{
    std::vector<std::string> files;

    // test for empty root path
    if (root_path.empty())
    {
        root_path = ".";
    }

    std::stack<std::string> directories, tempstack;
    directories.push(root_path);
    std::string path = "";

    while (!directories.empty())
    {
        path = directories.top();
        directories.pop();

        DIR *root = opendir(path.c_str());

        if (root)
        {
            struct dirent *root_file;
            struct stat _buff;
            DIR *subdir;

            while ((root_file = readdir(root)))
            {
                // check to see if it is a folder!
                if (stat(root_file->d_name, &_buff) != 0x4)
                {
                    // ignore '.' and '..' folder names, which are current and parent folder relative paths
                    if ((strcmp(root_file->d_name, ".") != 0) && (strcmp(root_file->d_name, "..") != 0))
                    {
                        std::string subpath = path + "/" + root_file->d_name;

                        if (recursive_search)
                        {
                            subdir = opendir(subpath.c_str());
                            if (subdir)
                            {
                                tempstack.push(subpath);
                                closedir(subdir);
                            }
                        }
                    }
                }
                // check to see if it is a file with the appropriate extension
                std::string tmp = root_file->d_name;
                if (tmp.find(extension.c_str()) != std::string::npos)
                {
                    // file with extension found! add to files list with full path
                    std::string fullpath = path + "/" + tmp;
                    files.push_back(fullpath);
                }
            }
        }
        closedir(root);
        // Directories are added to tempstack in A->Z order, which makes them pop from Z->A. This Makes sure that directories are
        // searched in the proper order and that the final output is in the proper order.
        while (!tempstack.empty()){
            directories.push(tempstack.top());
            tempstack.pop();
        }
    }
    return files;
}
开发者ID:8Z,项目名称:Cataclysm-DDA,代码行数:83,代码来源:file_finder.cpp

示例11: main

int main(int argc, const char *argv[])
{
    struct dirent *dp;
    DIR *dfd;
    char filename[20][50] = {0};
    char name[50] = {0};
    int i;
    int fd, rd;
    struct input_event ev[64];

    signal(SIGINT,event_exit);

    dfd = opendir("/dev/input");
    if(!dfd)
    {
        perror("opendir");
        return 1;
    }

    while(dp = readdir(dfd))
    {
        if(strncmp(dp->d_name,"event",5));
        else
            sprintf(filename[filenum++],"/dev/input/%s",dp->d_name);
    }
    closedir(dfd);

    printf("your input devices :\n");
    for (i = 0; i < filenum; i++) 
    {
        if((fds[i] = open(filename[i], O_RDONLY)) < 0)
        {
            perror("open");
            return 1;
        }

        if(ioctl(fds[i],EVIOCGNAME(sizeof(name)),name));
        printf("%d :%s\n",i,name);
    }

    int num = 0;
    printf("which is your choice:");
    scanf("%d",&num);

    fd = fds[num];

    while (1) 
    {
        rd = read(fd, ev, sizeof(struct input_event) * 4);
        if (rd < (int) sizeof(struct input_event)) 
        {
            perror("read");
            return 1;
        }

        for (i = 0; i < rd / sizeof(struct input_event); i++)
        {
            switch(ev[i].type)
            {
                case EV_KEY:
                    printf("Event: time %ld.%ld, type %s, code %d (%s), value %d\n",
                            ev[i].time.tv_sec, ev[i].time.tv_usec, 
                            "Key",
                            ev[i].code,
                            keys[ev[i].code],
                            ev[i].value);
                    break;

                case EV_ABS:
                    printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
                            ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
                            "Absolute",
                            ev[i].code,
                            absolutes[ev[i].code],
                            ev[i].value);
                    break;

                case EV_REL:
                    printf("Event: time %ld.%06ld, type %d (%s), code %d (%s), value %d\n",
                            ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
                            "Relative",
                            ev[i].code,
                            relatives[ev[i].code],
                            ev[i].value);
                    break;

                default:
                    break;
            }//end switch
        }//end for
    }//end while

    return 0;
}
开发者ID:jokerNi,项目名称:study,代码行数:94,代码来源:event.c

示例12: parse_include

/*
 *	Parse an "include filename" statement
 *
 *	FIXME: Tie this file into the CONF_SECTION for HUP handling!
 */
static int parse_include(policy_lex_file_t *lexer)
{
	char *p;
	policy_lex_t token;
	char filename[1024];
	char buffer[2048];

	token = policy_lex_file(lexer, 0, filename, sizeof(filename));
	if (token != POLICY_LEX_DOUBLE_QUOTED_STRING) {
		fprintf(stderr, "%s[%d]: Expected filename, got \"%s\"\n",
			lexer->filename, lexer->lineno,
			fr_int2str(rlm_policy_tokens, token, "?"));
		return 0;
	}

	/*
	 *	See if we're including all of the files in a subdirectory.
	 */
	strlcpy(buffer, lexer->filename, sizeof(buffer));
	p = strrchr(buffer, '/');
	if (p) {
		strlcpy(p + 1, filename, sizeof(buffer) - 1 - (p - buffer));

#ifdef HAVE_DIRENT_H
		p = strrchr(p + 1, '/');
		if (p && !p[1]) {
			DIR		*dir;
			struct dirent	*dp;

			p++;

			dir = opendir(buffer);
			if (!dir) {
				fprintf(stderr, "%s[%d]: Error opening %s:%s\n",
					lexer->filename, lexer->lineno,
					buffer, strerror(errno));
				return 0;
			}

			/*
			 *	Read the directory, ignoring "." files.
			 */
			while ((dp = readdir(dir)) != NULL) {
				struct stat buf;

				if (cf_exclude_file(dp->d_name)) continue;

				strlcpy(p, dp->d_name,
					sizeof(buffer) - (p - buffer));

				if ((stat(buffer, &buf) != 0) ||
				    S_ISDIR(buf.st_mode)) continue;

				debug_tokens("\nincluding file %s\n", buffer);
				if (!rlm_policy_parse(lexer->policies, buffer)) {
					closedir(dir);
					return 0;
				}
			}
			closedir(dir);
			return 1;
		} /* else it must have been a normalx file */
#endif
	} else {
		snprintf(buffer, sizeof(buffer), "%s/%s",
			 radius_dir, filename);
	}

	/*
	 *	Handle one include file.
	 */
	debug_tokens("\nincluding file %s\n", buffer);
	if (!rlm_policy_parse(lexer->policies, buffer)) {
		return 0;
	}

	return 1;
}
开发者ID:greendev5,项目名称:freeradius-server-wasel,代码行数:83,代码来源:parse.c

示例13: scan_loop

static int scan_loop(void)
{
	unsigned char req_data[MAX_PACKET_LEN];
	int len;
	DIR *wimax_dir;
	FILE *wimax_file;

	while (1)
	{
		if((wimax_dir = opendir("/tmp/wimax")) == NULL)
			mkdir("/tmp/wimax", 0777);
		else
			closedir(wimax_dir);

		if (wd_status.link_status == 0) {
			len = fill_find_network_req(req_data, 1);
			set_data(req_data, len);

			process_events_by_mask(5000, WDS_LINK_STATUS);

			if((wimax_file = fopen("/tmp/wimax/link_status", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.link_status);
				fclose(wimax_file);
			}

			wmlog_msg(2, "Network not found.");
		} else {
			len = fill_connection_params_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_RSSI | WDS_CINR | WDS_TXPWR | WDS_FREQ | WDS_BSID);

			wmlog_msg(0, "RSSI: %d   CINR: %f   TX Power: %d   Frequency: %d", wd_status.rssi, wd_status.cinr, wd_status.txpwr, wd_status.freq);
			wmlog_msg(0, "BSID: %02x:%02x:%02x:%02x:%02x:%02x", wd_status.bsid[0], wd_status.bsid[1], wd_status.bsid[2], wd_status.bsid[3], wd_status.bsid[4], wd_status.bsid[5]);

			if((wimax_file = fopen("/tmp/wimax/link_status", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.link_status);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/mac", "w+")) != NULL){
				fprintf(wimax_file, "%02x:%02x:%02x:%02x:%02x:%02x", wd_status.mac[0], wd_status.mac[1], wd_status.mac[2], wd_status.mac[3], wd_status.mac[4], wd_status.mac[5]);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/rssi", "w+")) != NULL){
				fprintf(wimax_file, "%hd", wd_status.rssi);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/cinr", "w+")) != NULL){
				fprintf(wimax_file, "%f", wd_status.cinr);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/bsid", "w+")) != NULL){
				fprintf(wimax_file, "%02x:%02x:%02x:%02x:%02x:%02x", wd_status.bsid[0], wd_status.bsid[1], wd_status.bsid[2], wd_status.bsid[3], wd_status.bsid[4], wd_status.bsid[5]);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/txpwr", "w+")) != NULL){
				fprintf(wimax_file, "%hu", wd_status.txpwr);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/freq", "w+")) != NULL){
				fprintf(wimax_file, "%u", wd_status.freq);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/state", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.state);
				fclose(wimax_file);
			}

			len = fill_state_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_STATE);

			wmlog_msg(2, "State: %s   Number: %d   Response: %d", wimax_states[wd_status.state], wd_status.state, wd_status.link_status);

			if (first_nego_flag) {
				first_nego_flag = 0;
				len = fill_find_network_req(req_data, 2);
				set_data(req_data, len);
			}

			process_events_by_mask(5000, WDS_LINK_STATUS);
		}
		
		sleep(SCAN_INTERVAL);
	}

	return 0;
}
开发者ID:StephenMacras,项目名称:dsl-n55u-bender,代码行数:96,代码来源:wimax.c

示例14: I18nCurrentLanguage

cInstallPrimLang::cInstallPrimLang() :cInstallSubMenu(tr("Handling"))
{
    for (int k = 0; k < 256; k++)
        city_values[k] = NULL;

    // Language
    osdLanguageIndex = I18nCurrentLanguage();

    askTimeZone = true;
#ifdef RBMINI
    cPlugin *p = cPluginManager::GetPlugin("avahi");
    if (p)
    {
        std::vector < ReelBox_t > ReelBoxes;
        p->Service("Avahi ReelBox-List", &ReelBoxes);

        if (ReelBoxes.size() > 0)
        {
            // save changes in sysconfig variable in vdr into sysconfig file
            cSysConfig_vdr::GetInstance().Save();

            std::string cmd;
            // get the timezone from an AVG
            if (strlen(Setup.NetServerIP))
            {                   // there was already one configured, let's take this one...
                // TB: but only if it's available
                bool serverAvailable = false;
                for (unsigned int i = 0; i < ReelBoxes.size(); i++)
                    if (strcmp(Setup.NetServerIP, ReelBoxes.at(i).Ip.c_str()) == 0)
                        serverAvailable = true;
                if (serverAvailable)
                    cmd = std::string("getConfigsFromAVGServer.sh ") + Setup.NetServerIP + std::string(" sysconfig ; ");
                else
                    cmd = std::string("getConfigsFromAVGServer.sh ") + ReelBoxes.at(0).Ip + std::string(" sysconfig ; ");
            }
            else
                cmd = std::string("getConfigsFromAVGServer.sh ") + ReelBoxes.at(0).Ip + std::string(" sysconfig ; ");
            SystemExec(cmd.c_str());    // changes /etc/default/sysconfig

            cSysConfig_vdr::GetInstance().Load(SYSCONFIGFNAME); // load the changes in file into vdr
            dsyslog("(%s:%d) ... done loading sysconfig.", __FILE__, __LINE__);
        }

        // one or more reelbox avantgarde donot ask for TimeZone
        // it is got from the first avantgarde in the list
        askTimeZone = (ReelBoxes.size() == 0);
    }
#endif
    if (askTimeZone)
    {
        // Timezone
        currentCity = 0;
        nr_city_values = 1;
        DIR *zoneDir = NULL;
        struct dirent *entry = NULL;
        struct stat buf;
        std::string path = "/usr/share/zoneinfo";
        for (int k = 0; k < 256; k++)
        {
            city_values[k] = (char *)malloc(32);
            city_values[k][0] = '\0';
        }

        if ((zoneDir = opendir(path.c_str())) != NULL)
        {
            while ((entry = readdir(zoneDir)) != NULL)
            {
                if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
                {
                    std::string tmp = path + "/" + entry->d_name;
                    stat(tmp.c_str(), &buf);
                }
            }
            closedir(zoneDir);
        }
        else
            d(printf("Can not read directory \"%s\" because of error \"%s\"\n", path.c_str(), strerror(errno)))

        cSysConfig_vdr & sysconfig = cSysConfig_vdr::GetInstance();
        char *zoneInfo = strdup((char *)sysconfig.GetVariable("ZONEINFO"));

        char *buf2;
        char *continent = NULL;
        char *city = NULL;

        continent = strdup(strtok_r(zoneInfo, "/", &buf2)); /* go to first '/' */
        city = strdup(strtok_r(NULL, "/", &buf2));  /* get the rest */

        free(zoneInfo);

        if (city != NULL)
        {
            nr_city_values = 0;
            DIR *conDir = NULL;
            struct dirent *entry = NULL;
            struct stat buf;
            std::string path = "/usr/share/zoneinfo/Europe";

            if ((conDir = opendir(path.c_str())) != NULL)
            {
//.........这里部分代码省略.........
开发者ID:suborb,项目名称:reelvdr,代码行数:101,代码来源:install_language.c

示例15: __populate_fs


//.........这里部分代码省略.........
			read_cnt = readlink(name, ln_target,
					    sizeof(ln_target));
			if (read_cnt == -1) {
				com_err(__func__, errno,
					_("while trying to readlink \"%s\""),
					name);
				return errno;
			}
			ln_target[read_cnt] = '\0';
			retval = do_symlink_internal(fs, parent_ino, name,
						     ln_target, root);
			if (retval) {
				com_err(__func__, retval,
					_("while writing symlink\"%s\""),
					name);
				return retval;
			}
			break;
		case S_IFREG:
			retval = do_write_internal(fs, parent_ino, name, name,
						   root);
			if (retval) {
				com_err(__func__, retval,
					_("while writing file \"%s\""), name);
				return retval;
			}
			break;
		case S_IFDIR:
			retval = do_mkdir_internal(fs, parent_ino, name, &st,
						   root);
			if (retval) {
				com_err(__func__, retval,
					_("while making dir \"%s\""), name);
				return retval;
			}
			retval = ext2fs_namei(fs, root, parent_ino,
					      name, &ino);
			if (retval) {
				com_err(name, retval, 0);
					return retval;
			}
			/* Populate the dir recursively*/
			retval = __populate_fs(fs, ino, name, root, hdlinks);
			if (retval) {
				com_err(__func__, retval,
					_("while adding dir \"%s\""), name);
				return retval;
			}
			if (chdir("..")) {
				com_err(__func__, errno,
					_("during cd .."));
				return errno;
			}
			break;
		default:
			com_err(__func__, 0,
				_("ignoring entry \"%s\""), name);
		}

		retval =  ext2fs_namei(fs, root, parent_ino, name, &ino);
		if (retval) {
			com_err(name, retval, 0);
			return retval;
		}

		retval = set_inode_extra(fs, parent_ino, ino, &st);
		if (retval) {
			com_err(__func__, retval,
				_("while setting inode for \"%s\""), name);
			return retval;
		}

		/* Save the hardlink ino */
		if (save_inode) {
			/*
			 * Check whether need more memory, and we don't need
			 * free() since the lifespan will be over after the fs
			 * populated.
			 */
			if (hdlinks->count == hdlinks->size) {
				void *p = realloc(hdlinks->hdl,
						(hdlinks->size + HDLINK_CNT) *
						sizeof(struct hdlink_s));
				if (p == NULL) {
					com_err(name, errno,
						_("Not enough memory"));
					return errno;
				}
				hdlinks->hdl = p;
				hdlinks->size += HDLINK_CNT;
			}
			hdlinks->hdl[hdlinks->count].src_dev = st.st_dev;
			hdlinks->hdl[hdlinks->count].src_ino = st.st_ino;
			hdlinks->hdl[hdlinks->count].dst_ino = ino;
			hdlinks->count++;
		}
	}
	closedir(dh);
	return retval;
}
开发者ID:Gwinel,项目名称:e2fsprogs,代码行数:101,代码来源:create_inode.c


注:本文中的closedir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。