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


C++ rewinddir函数代码示例

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


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

示例1: Mono_Posix_Syscall_rewinddir

int
Mono_Posix_Syscall_rewinddir (void* dir)
{
	rewinddir (dir);
	return 0;
}
开发者ID:AveProjVstm,项目名称:MonoVstm,代码行数:6,代码来源:dirent.c

示例2: scandirect

void	scandirect ( char *dirname )
{
	DIR *dir;
	char	**names;
	long	numfiles;
	int	longest;
	struct dirent *ent;
	int i;
	int	chrs;
	struct stat buf;
	char pathname[1024];

	if ( (dir=opendir(dirname)) == NULL )
		return;

	i = 0;
	chrs = 0;
	longest = 0;
	numfiles = 0;

	while ( (ent = readdir (dir)) != NULL )
	{
		numfiles++;
	}

	names = (char **) malloc ( numfiles * sizeof (char *) );

	rewinddir(dir);

	while ( (ent = readdir (dir)) != NULL )
	{
		names[i] = (char *) malloc ( strlen(ent->d_name) );

		strcpy( names[i], ent->d_name );

		printf("%s", names[i]);
		chrs += strlen (names[i]);

		if ( i%5 == 0 )
		{
			printf("\n");
			chrs = 0;
		}
		else
		{
			while ( chrs%14 != 0)
			{
				printf(" ");
				chrs++;
			}
		}

		i++;
	}
	printf ("\n");

	if (closedir(dir) != 0)
	{
		perror("mkern: Error closing directory.\n");
		exit (1);
	}
}
开发者ID:craigsapp,项目名称:humdrum,代码行数:62,代码来源:scand.c

示例3: report

char *get_file_list(const char *dirname, int file_type, uint32_t *count)
{

    DIR           *pdir = NULL;
    struct dirent *pdirent = NULL;
    int           curr_offset = 0;
    int           byte_count = 0;
    int           file_count = 0;
    char          *ret_str = NULL;
    char          filename[MAX_PATH_SIZE];
    int           cond1, cond2;

    if ((dirname == NULL) || ((pdir = opendir(dirname)) == NULL )) {
        if (dirname == NULL) {
            report("%s %s:line %d %s", __FILE__, __FUNCTION__, __LINE__,
                   "NULL directory is passed as parameter to funtion");
        } else {
            report("%s %s:line %d Error in opening the dir %s", __FILE__,
                   __FUNCTION__, __LINE__, dirname);
        }
        if (count)
            *count = 0;
        return NULL;
    }

    while (1) {
        if ((pdirent = readdir(pdir)) == NULL)
            break;

        /* Skip over '.' and '..' directores */
        if ((pdirent->d_name[0] == '.') ||
            !strcmp(pdirent->d_name, FILENAME_NUM_REF))
            continue;
        
        sprintf(filename, "%s/%s", dirname, pdirent->d_name);
        cond1 = (file_type == FILE_TYPE) && is_directory(filename);
        cond2 = (file_type == DIR_TYPE) && (!is_directory(filename));

        if (cond1 || cond2)
            continue;

        /* Calculate the number of bytes for this new entry.*/                    
        byte_count += strlen(pdirent->d_name) + 1;
        file_count++;
    }
    if (count)
        *count = file_count;
    
    if (file_count != 0) {
        
        /* need one extra one for the finall NULL terminator*/
        if ((ret_str = (char *) malloc(byte_count + 1)) == NULL) {
            report("get_file_list() failed to malloc(%d)",byte_count+1);
            closedir(pdir);
            return NULL;
        }    
        
        rewinddir(pdir);
        
        while (file_count != 0) {
            if ((pdirent = readdir(pdir)) == NULL)
                break;

            if ((pdirent->d_name[0] == '.') ||
                !strcmp(pdirent->d_name, FILENAME_NUM_REF))
                continue;
            
            sprintf(filename, "%s/%s", dirname, pdirent->d_name);
            cond1 = (file_type == FILE_TYPE) && is_directory(filename);
            cond2 = (file_type == DIR_TYPE) && (!is_directory(filename));

            if (cond1 || cond2)
                continue;

            strcpy(ret_str + curr_offset, pdirent->d_name);
            curr_offset = curr_offset + strlen(pdirent->d_name) + 1;
            file_count--;
        }
        /* Put in the finall null terminator*/
        ret_str[byte_count] = '\0';
    }
    closedir(pdir);
    return ret_str;
}
开发者ID:DCteam,项目名称:lustre,代码行数:84,代码来源:lustre-snmp-util.c

示例4: POSIXFSAL_readdir

/**
 * FSAL_readdir :
 *     Read the entries of an opened directory.
 *     
 * \param dir_descriptor (input):
 *        Pointer to the directory descriptor filled by FSAL_opendir.
 * \param start_position (input):
 *        Cookie that indicates the first object to be read during
 *        this readdir operation.
 *        This should be :
 *        - FSAL_READDIR_FROM_BEGINNING for reading the content
 *          of the directory from the beginning.
 *        - The end_position parameter returned by the previous
 *          call to FSAL_readdir.
 * \param get_attr_mask (input)
 *        Specify the set of attributes to be retrieved for directory entries.
 * \param buffersize (input)
 *        The size (in bytes) of the buffer where
 *        the direntries are to be stored.
 * \param pdirent (output)
 *        Adresse of the buffer where the direntries are to be stored.
 * \param end_position (output)
 *        Cookie that indicates the current position in the directory.
 * \param nb_entries (output)
 *        Pointer to the number of entries read during the call.
 * \param end_of_dir (output)
 *        Pointer to a boolean that indicates if the end of dir
 *        has been reached during the call.
 * 
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - Another error code if an error occured.
 */
fsal_status_t POSIXFSAL_readdir(fsal_dir_t * dir_descriptor,     /* IN */
                                fsal_cookie_t start_pos,      /* IN */
                                fsal_attrib_mask_t get_attr_mask,       /* IN */
                                fsal_mdsize_t buffersize,       /* IN */
                                fsal_dirent_t * p_pdirent,      /* OUT */
                                fsal_cookie_t * end_position,    /* OUT */
                                fsal_count_t * p_nb_entries,    /* OUT */
                                fsal_boolean_t * p_end_of_dir   /* OUT */
    )
{
  posixfsal_dir_t * p_dir_descriptor = (posixfsal_dir_t *) dir_descriptor;
  posixfsal_cookie_t start_position, telldir_pos;
  posixfsal_cookie_t * p_end_position = (posixfsal_cookie_t *) end_position;
  fsal_status_t st;
  fsal_posixdb_status_t stdb;
  fsal_count_t max_dir_entries;
  struct dirent *dp;
  struct dirent dpe;
  struct stat buffstat;
  fsal_path_t fsalpath;
  fsal_posixdb_fileinfo_t infofs;
  int rc;

  /*****************/
  /* sanity checks */
  /*****************/

  if(!p_dir_descriptor || !p_pdirent || !p_end_position || !p_nb_entries || !p_end_of_dir)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_readdir);

  max_dir_entries = (buffersize / sizeof(fsal_dirent_t));

  /***************************/
  /* seek into the directory */
  /***************************/
  memcpy ( (char *)&start_position.data.cookie, (char *)&start_pos.data, sizeof( off_t ) ) ;

  errno = 0;
  if(start_position.data.cookie == 0)
    {
      rewinddir(p_dir_descriptor->p_dir);
      rc = errno;
    }
  else
    {
      seekdir(p_dir_descriptor->p_dir, start_position.data.cookie);
      rc = errno;
    }

  if(rc)
    {
      st.major = posix2fsal_error(rc);
      st.minor = rc;
      goto readdir_error;
    }

  /************************/
  /* browse the directory */
  /************************/

  *p_nb_entries = 0;
  while(*p_nb_entries < max_dir_entries)
    {
    /***********************/
      /* read the next entry */
    /***********************/
      TakeTokenFSCall();
//.........这里部分代码省略.........
开发者ID:MeghanaM,项目名称:nfs-ganesha,代码行数:101,代码来源:fsal_dirs.c

示例5: printdirs

/**
  * Meniul de navigare in fisiere
  */
void printdirs(struct DIR * dir){
	char namebuf [12];
	uint32_t size = 0;
	uint8_t bitmap = 0, selected = 0, cnt = 0, ret_code = 0, is=0;
	struct dirent * crt_dir;

	do{
		/* Afisam continutul directorului curent */
		rewinddir(dir);
		LCD_clear();
		cnt = 0;
		while(1){
			crt_dir = readdir( dir, buffer);
			ret_code = check (crt_dir);
			if(ret_code == DIR_INVALID)
				continue;
			if(ret_code == DIR_END)
				break;

			get_dirent_name(crt_dir, namebuf);
			if(cnt ++ == selected){
				LCD_str( namebuf,SELECTED );
			}else{
				LCD_str( namebuf, NOT_SELECTED);
			}
		}

		/* Asteptam sa selecteze un fisier sau director */
		bitmap = BTN_wait();

		switch(bitmap){
			case UP:
				selected = (selected +1)%cnt;
				continue;
			case DOWN:
				selected = (selected + cnt-1) % cnt;
				continue;
			case ENTER:
				rewinddir(dir);
				selected ++;
				while(1){
					crt_dir = readdir( dir, buffer);
					ret_code = check (crt_dir);
					if( ret_code == DIR_VALID) selected--;
					if( !selected ) break;
				}
				break;
			default:
				continue;

		}

		is_dir(crt_dir, &is);
		if( is){
			dir = opendir(crt_dir);
		}else{
			get_dirent_size(crt_dir, &size);
			open_f(crt_dir);

			/* Curatam ecranul si afisam poza */
			LCD_clear();
			draw_bmp();
			close_f();

			/* Asteptam sa apese butonul de exit */
			while( BTN_wait() != CLOSE);
		}
	}while(1);
	exit(EXIT_SUCCESS);
}
开发者ID:ctalau,项目名称:image-viewer,代码行数:73,代码来源:main.c

示例6: __getcwd


//.........这里部分代码省略.........
        mount_point = dotdev != thisdev;

        /* Search for the last directory.  */
#if HAVE_OPENAT_SUPPORT
        dirstream = fdopendir (fd);
        if (dirstream == NULL)
            goto lose;
        /* Reset fd.  It may have been closed by fdopendir.  */
        fd = dirfd (dirstream);
        fd_needs_closing = false;
#else
        dirstream = __opendir (dotlist);
        if (dirstream == NULL)
            goto lose;
        dotlist[dotlen++] = '/';
#endif
        for (;;)
        {
            /* Clear errno to distinguish EOF from error if readdir returns
               NULL.  */
            __set_errno (0);
            d = __readdir (dirstream);

            /* When we've iterated through all directory entries without finding
               one with a matching d_ino, rewind the stream and consider each
               name again, but this time, using lstat.  This is necessary in a
               chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where
               .., ../.., ../../.., etc. all had the same device number, yet the
               d_ino values for entries in / did not match those obtained
               via lstat.  */
            if (d == NULL && errno == 0 && use_d_ino)
            {
                use_d_ino = false;
                rewinddir (dirstream);
                d = __readdir (dirstream);
            }

            if (d == NULL)
            {
                if (errno == 0)
                    /* EOF on dirstream, which can mean e.g., that the current
                       directory has been removed.  */
                    __set_errno (ENOENT);
                goto lose;
            }
            if (d->d_name[0] == '.' &&
                    (d->d_name[1] == '\0' ||
                     (d->d_name[1] == '.' && d->d_name[2] == '\0')))
                continue;

            if (use_d_ino)
            {
                bool match = (MATCHING_INO (d, thisino) || mount_point);
                if (! match)
                    continue;
            }

            {
                int entry_status;
#if HAVE_OPENAT_SUPPORT
                entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW);
#else
                /* Compute size needed for this file name, or for the file
                   name ".." in the same directory, whichever is larger.
                   Room for ".." might be needed the next time through
                   the outer loop.  */
开发者ID:kkodani,项目名称:cs35L,代码行数:67,代码来源:getcwd.c

示例7: main

/******************************************************************************
 This function creates a dirctory and file as specified by the input argruments.
 It is used to verify that a file create and delete work as expected.
 The sequence is as follows:
    create directory
    create file in directory
    verify file exists in directory
    remove file
    verify file no longer exists in directory
*******************************************************************************/
int main(int argc, char *argv[])
{
   DIR *dir_ptr;
   struct dirent *file_ptr;
   int dir_status;
   char *path;
   char *filename;
   FILE *test_file_ptr;
   char full_path[128];
   int read_return;
   int dir_remove;
   int return_value=0;


   // Input arguments are directory and filename
   if (argc > 2) {
       path = strdup(argv[1]);
       filename = strdup(argv[2]); 
       sprintf(full_path,"%s/%s",path,filename);
       printf("%s\n", full_path);  
   }
   else {
       printf("ERROR: Path and/or file not specified\n");
       printf("Usage:  ./readdir_test path filename\n");
       return 1;
   }

   // Make the directory
   if ((dir_status=mkdir(path, S_IRWXU))== 0) {
     printf("Directory created\n");
   } 

   // Open the directory
   if ((dir_ptr = opendir(path)) == NULL) {
     printf("Error:  Could not open directory\n");
     return_value=1;
   }
   // Create a file
   else {
     printf("Going to create file %s\n", full_path);
     test_file_ptr = fopen(full_path, "w");
     if (test_file_ptr == NULL) {
        printf("Error:  NULL returned on file create \n");
       return_value=1;
     }    
     else {
       printf("Successfully created file\n");
       // close the directory and file
       fclose(test_file_ptr);
       closedir(dir_ptr);
     }
   }
   // Open the directory again}
   if ((dir_ptr = opendir(path)) == NULL) {
     printf("Error:  Could not open directory\n");
       return_value=1;
   }
   printf("Going to read directory %s to make sure file %s found %s\n", path,filename);
   read_return = read_directory(file_ptr, dir_ptr, filename);
   // File should be found in directory
   if (read_return != 0) {
       printf("Error: expected file %s to be present but was not\n", full_path);  
       return_value=1;
   }
   // Delete the file
   printf("Going to delete %s\n", full_path);
   unlink(full_path);
   printf("Reading directory after deleteing file %s\n", full_path);
   rewinddir(dir_ptr);

   // File should no longer be present
   read_return = read_directory(file_ptr, dir_ptr, filename);
   if (read_return == 0) {
       printf("Error: expected file %s to not be present but was\n", full_path);  
       return_value=1;
   }
   closedir(dir_ptr);
   dir_remove = rmdir(path);
   if (dir_remove != 0) {
      printf("Error: Directoy %s cannot be removed\n",path);
   }    
   return return_value;
}
开发者ID:aCaldwell,项目名称:plfs-regression,代码行数:93,代码来源:dir_ops.c

示例8: osd_get_drive_list

int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives)
{
	struct osd_drive_description *ret = NULL;
	struct dirent *entry;
	int count, fd, type;
	char buf[512];
	char *serial;
	DIR *toplevel;

	/*
	 * Walk through /dev/bsg to find available devices.  Could look
	 * through /sys/class/bsg, but would have to create each device
	 * by hand in /tmp somewhere to use it, or figure out the mapping
	 * in /dev anyway.
	 */
	count = 0;
	toplevel = opendir("/dev/bsg");
	if (!toplevel)
		goto out;

	/* First, get the count */
	while ((entry = readdir(toplevel)))
		++count;

	/* subtract 2 for . and .. */
	count -= 2;

	if (count <= 0)
		goto out;

	ret = malloc(count * sizeof(*ret));
	memset(ret, 0, count * sizeof(*ret));
	rewinddir(toplevel);
	count = 0;
	while ((entry = readdir(toplevel))) {
		if (entry->d_name[0] == '.')
			continue;
		snprintf(buf, sizeof(buf),
		         "/sys/class/scsi_device/%s/device/type",
		         entry->d_name);
		fd = open(buf, O_RDONLY);
		if (fd < 0)
			continue;

		type = 0;
		buf[0] = '\0';
		read(fd, buf, sizeof(buf));
		sscanf(buf, "%d", &type);
		close(fd);

		if (type != 17)  /* TYPE_OSD */
			continue;

		snprintf(buf, sizeof(buf), "/dev/bsg/%s", entry->d_name);

		fd = open(buf, O_RDWR);
		if (fd < 0)
			continue;

		serial = osd_get_drive_serial(fd);
		close(fd);

		if (!serial)
			continue;

		ret[count].targetname = serial;
		ret[count].chardev = strdup(buf);
		++count;
	}

out:
	if (toplevel)
		closedir(toplevel);
	*drives = ret;
	*num_drives = count;
	return 0;
}
开发者ID:snsl,项目名称:osc-osd,代码行数:77,代码来源:drivelist.c

示例9: main

/**
 * Main method
 */
int main(int argc, char *argv[])
{
	if (argc < 2)
	{
		printf("Usage: mkrcpt <location to watch>\n");
		return -1;
	}
	
	DIR *dp = opendir(argv[1]);
	if (dp == NULL)
	{
		printf("Could not open the directory\n");
		return -1;
	}
	
	char *recpt = malloc(sizeof(char) * 1024);
	snprintf(recpt, 1024, REPOS_ITEM, getenv("HOME"), "test");
			
	FILE *fp = fopen(recpt, "w");
	if (fp == NULL)
	{
		char *repospath = malloc(sizeof(char) * 256);
		snprintf(repospath, 256, REPOS, getenv("HOME"));
		
		// could not open the recipt, try making the directory go again
		DIR *dest = opendir(repospath);
		if (dest == NULL)
		{
			if (mkdir(repospath, 0700) != 0)
			{
				printf("Could not create receipts directory\n");
				free(repospath);
				return -2;
			}
			fp = fopen(recpt, "w");
			if (ferror(fp))
			{
				printf("Failed to create receipt\n");
				free(repospath);
				return -2;
			}
		}
		else
		{
			printf("Failed to create recipt\n");
			free(repospath);
			return -1;
		}
	}
	fwrite(&HEADER, sizeof(HEADER), 1, fp);
	
	time_t install_time;
	assert(time(&install_time) != 0);
	fwrite(&install_time, sizeof(time_t), 1, fp);
	
	fputc('\2', fp);
	
	// open the temporary before list
	int pathsize = strlen(recpt) + 3;
	
	char *temppath = malloc(pathsize * sizeof(char));
	snprintf(temppath, pathsize, "%s.1", recpt);
	FILE *befp = fopen(temppath, "w+");
	record_files(argv[1], dp, befp);
	fputc('\0', befp);
	
	// install
	system("make install");
	
	// open the temporary after list
	rewinddir(dp);
	
	temppath[strlen(temppath) - 1] = '2';
	FILE *affp = fopen(temppath, "w+");
	record_files(argv[1], dp, affp);
	fputc('\0', affp);
	
	// compare the two file lists
	rewind(befp);
	rewind(affp);
	
	compare_records(fp, befp, affp);
	
	fclose(befp);
	fclose(affp);
	
	// remove the two temps
	unlink(temppath);
	temppath[strlen(temppath) - 1] = '1';
	unlink(temppath);
	free(temppath);
	
	// finish cleaning up
	fputc('\0', fp);
	
	fclose(fp);
	closedir(dp);
//.........这里部分代码省略.........
开发者ID:pnd10,项目名称:Toolchain,代码行数:101,代码来源:mkrcpt.c

示例10: assert

/// The real implementation of wildcard expansion is in this function. Other functions are just
/// wrappers around this one.
///
/// This function traverses the relevant directory tree looking for matches, and recurses when
/// needed to handle wildcrards spanning multiple components and recursive wildcards.
///
/// Because this function calls itself recursively with substrings, it's important that the
/// parameters be raw pointers instead of wcstring, which would be too expensive to construct for
/// all substrings.
///
/// Args:
/// base_dir: the "working directory" against which the wildcard is to be resolved
/// wc: the wildcard string itself, e.g. foo*bar/baz (where * is acutally ANY_CHAR)
/// prefix: the string that should be prepended for completions that replace their token.
//    This is usually the same thing as the original wildcard, but for fuzzy matching, we
//    expand intermediate segments. effective_prefix is always either empty, or ends with a slash
//    Note: this is only used when doing completions (EXPAND_FOR_COMPLETIONS is true), not
//    expansions
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
                                 const wcstring &effective_prefix) {
    assert(wc != NULL);

    if (interrupted()) {
        return;
    }

    // Get the current segment and compute interesting properties about it.
    const size_t wc_len = std::wcslen(wc);
    const wchar_t *const next_slash = std::wcschr(wc, L'/');
    const bool is_last_segment = (next_slash == NULL);
    const size_t wc_segment_len = next_slash ? next_slash - wc : wc_len;
    const wcstring wc_segment = wcstring(wc, wc_segment_len);
    const bool segment_has_wildcards =
        wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */);
    const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : NULL;

    if (wc_segment.empty()) {
        // Handle empty segment.
        assert(!segment_has_wildcards);  //!OCLINT(multiple unary operator)
        if (is_last_segment) {
            this->expand_trailing_slash(base_dir, effective_prefix);
        } else {
            // Multiple adjacent slashes in the wildcard. Just skip them.
            this->expand(base_dir, wc_remainder, effective_prefix + L'/');
        }
    } else if (!segment_has_wildcards && !is_last_segment) {
        // Literal intermediate match. Note that we may not be able to actually read the directory
        // (issue #2099).
        assert(next_slash != NULL);

        // Absolute path of the intermediate directory
        const wcstring intermediate_dirpath = base_dir + wc_segment + L'/';

        // This just trumps everything.
        size_t before = this->resolved_completions->size();
        this->expand(intermediate_dirpath, wc_remainder, effective_prefix + wc_segment + L'/');

        // Maybe try a fuzzy match (#94) if nothing was found with the literal match. Respect
        // EXPAND_NO_DIRECTORY_ABBREVIATIONS (issue #2413).
        // Don't do fuzzy matches if the literal segment was valid (#3211)
        bool allow_fuzzy = (this->flags & (EXPAND_FUZZY_MATCH | EXPAND_NO_FUZZY_DIRECTORIES)) ==
                           EXPAND_FUZZY_MATCH;
        if (allow_fuzzy && this->resolved_completions->size() == before &&
            waccess(intermediate_dirpath, F_OK) != 0) {
            assert(this->flags & EXPAND_FOR_COMPLETIONS);
            DIR *base_dir_fd = open_dir(base_dir);
            if (base_dir_fd != NULL) {
                this->expand_literal_intermediate_segment_with_fuzz(
                    base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix);
                closedir(base_dir_fd);
            }
        }
    } else {
        assert(!wc_segment.empty() && (segment_has_wildcards || is_last_segment));
        DIR *dir = open_dir(base_dir);
        if (dir) {
            if (is_last_segment) {
                // Last wildcard segment, nonempty wildcard.
                this->expand_last_segment(base_dir, dir, wc_segment, effective_prefix);
            } else {
                // Not the last segment, nonempty wildcard.
                assert(next_slash != NULL);
                this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder,
                                                  effective_prefix + wc_segment + L'/');
            }

            // Recursive wildcards require special handling.
            size_t asr_idx = wc_segment.find(ANY_STRING_RECURSIVE);
            if (asr_idx != wcstring::npos) {
                // Construct a "head + any" wildcard for matching stuff in this directory, and an
                // "any + tail" wildcard for matching stuff in subdirectories. Note that the
                // ANY_STRING_RECURSIVE character is present in both the head and the tail.
                const wcstring head_any(wc_segment, 0, asr_idx + 1);
                const wchar_t *any_tail = wc + asr_idx;
                assert(head_any.at(head_any.size() - 1) == ANY_STRING_RECURSIVE);
                assert(any_tail[0] == ANY_STRING_RECURSIVE);

                rewinddir(dir);
                this->expand_intermediate_segment(base_dir, dir, head_any, any_tail,
                                                  effective_prefix);
//.........这里部分代码省略.........
开发者ID:ridiculousfish,项目名称:fish-shell,代码行数:101,代码来源:wildcard.cpp

示例11: virNodeParseNode

virNodeParseNode(const char *node,
                 int *sockets,
                 int *cores,
                 int *threads,
                 int *offline)
{
    int ret = -1;
    int processors = 0;
    DIR *cpudir = NULL;
    struct dirent *cpudirent = NULL;
    int sock_max = 0;
    cpu_set_t sock_map;
    int sock;
    cpu_set_t *core_maps = NULL;
    int core;
    size_t i;
    int siblings;
    unsigned int cpu;
    int online;

    *threads = 0;
    *cores = 0;
    *sockets = 0;

    if (!(cpudir = opendir(node))) {
        virReportSystemError(errno, _("cannot opendir %s"), node);
        goto cleanup;
    }

    /* enumerate sockets in the node */
    CPU_ZERO(&sock_map);
    errno = 0;
    while ((cpudirent = readdir(cpudir))) {
        if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
            continue;

        if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
            goto cleanup;

        if (!online)
            continue;

        /* Parse socket */
        if ((sock = virNodeParseSocket(node, cpu)) < 0)
            goto cleanup;
        CPU_SET(sock, &sock_map);

        if (sock > sock_max)
            sock_max = sock;

        errno = 0;
    }

    if (errno) {
        virReportSystemError(errno, _("problem reading %s"), node);
        goto cleanup;
    }

    sock_max++;

    /* allocate cpu maps for each socket */
    if (VIR_ALLOC_N(core_maps, sock_max) < 0)
        goto cleanup;

    for (i = 0; i < sock_max; i++)
        CPU_ZERO(&core_maps[i]);

    /* iterate over all CPU's in the node */
    rewinddir(cpudir);
    errno = 0;
    while ((cpudirent = readdir(cpudir))) {
        if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
            continue;

        if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
            goto cleanup;

        if (!online) {
            (*offline)++;
            continue;
        }

        processors++;

        /* Parse socket */
        if ((sock = virNodeParseSocket(node, cpu)) < 0)
            goto cleanup;
        if (!CPU_ISSET(sock, &sock_map)) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("CPU socket topology has changed"));
            goto cleanup;
        }

        /* Parse core */
# if defined(__s390__) || \
    defined(__s390x__)
        /* logical cpu is equivalent to a core on s390 */
        core = cpu;
# else
        core = virNodeGetCpuValue(node, cpu, "topology/core_id", 0);
//.........这里部分代码省略.........
开发者ID:heidsoft,项目名称:libvirt,代码行数:101,代码来源:nodeinfo.c

示例12: npfs_read_dir

static u32
npfs_read_dir(Fid *f, u8* buf, u64 offset, u32 count, int dotu)
{
	int i, n, plen;
	char *dname, *path;
	struct dirent *dirent;
	struct stat st;
	Spwstat wstat;

	if (offset == 0) {
		rewinddir(f->dir);
		f->diroffset = 0;
	}

	plen = strlen(f->path);
	n = 0;
	dirent = NULL;
	dname = f->direntname;
	while (n < count) {
		if (!dname) {
			dirent = readdir(f->dir);
			if (!dirent)
				break;

			if (strcmp(dirent->d_name, ".") == 0
			|| strcmp(dirent->d_name, "..") == 0)
				continue;

			dname = dirent->d_name;
		}

		path = malloc(plen + strlen(dname) + 2);
		sprintf(path, "%s/%s", f->path, dname);
		
		if (lstat(path, &st) < 0) {
			free(path);
			create_rerror(errno);
			return 0;
		}

		ustat2npwstat(path, &st, &wstat, dotu);
		i = sp_serialize_stat(&wstat, buf + n, count - n - 1, dotu);
		free(wstat.extension);
		free(path);
		path = NULL;
		if (i==0)
			break;

		dname = NULL;
		n += i;
	}

	if (f->direntname) {
		free(f->direntname);
		f->direntname = NULL;
	}

	if (dirent)
		f->direntname = strdup(dirent->d_name);

	f->diroffset += n;
	return n;
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:63,代码来源:ufs.c

示例13: do_cmd

static int do_cmd(int cmd, port_addr fd)
{
    switch(cmd)
    {
        case 0:
        {
            // Identify command

            // Read the command crc
            uint32_t ccrc;
            serial_read(fd, &ccrc, 4);
            uint32_t eccrc = crc32((void *)0, 0);
            if(ccrc != eccrc)
                return send_error_msg(fd, CRC_ERROR);

            // Set the response length and error code
            uint32_t resp_length = 12;
            uint32_t error_code = SUCCESS;

            // Build the response crc
            uint32_t crc = crc32_start();
            crc = crc32_append(crc, &magic, 4);
            crc = crc32_append(crc, &resp_length, 4);
            crc = crc32_append(crc, &error_code, 4);
            crc = crc32_append(crc, &server_caps, 4);
            crc = crc32_finish(crc);

            // Send the response
            serial_write(fd, &magic, 4);
            serial_write(fd, &resp_length, 4);
            serial_write(fd, &error_code, 4);
            serial_write(fd, &server_caps, 4);
            serial_write(fd, &crc, 4);

            fprintf(stderr, "Sent CMD0 response\n");

            return 0;
        }

        case 1:
        {
            // Read directory
            uint32_t eccrc = crc32_start();

            // Read the directory name
            uint16_t dir_name_len;
            serial_read(fd, &dir_name_len, 2);
            eccrc = crc32_append(eccrc, &dir_name_len, 2);
            char *dir_name = (char *)malloc((int)dir_name_len + 1);
            memset(dir_name, 0, dir_name_len + 1);
            serial_read(fd, dir_name, (size_t)dir_name_len);
            eccrc = crc32_append(eccrc, dir_name, (size_t)dir_name_len);
            eccrc = crc32_finish(eccrc);

            // Read the command crc
            uint32_t ccrc;
            serial_read(fd, &ccrc, 4);
            if(ccrc != eccrc)
                return send_error_msg(fd, CRC_ERROR);

            // Append the requested dir to the base dir
            int full_dir_len = strlen(base_dir) + 1 + dir_name_len + 1;
            char *full_dir = (char *)malloc(full_dir_len);
            memset(full_dir, 0, full_dir_len);
            strcat(full_dir, base_dir);
            strcat(full_dir, "/");
            strcat(full_dir, dir_name);

            // Try and read the requested directory
            DIR *dirp = opendir(full_dir);
            if(dirp == NULL)
            {
                free(dir_name);
                free(full_dir);
                if((errno == ENOENT) || (errno == ENOTDIR))
                    return send_error_msg(fd, PATH_NOT_FOUND);
                else
                    return send_error_msg(fd, UNKNOWN_ERROR);
            }

            // Count the directory entries
            int byte_count = 0;
            uint32_t entry_count = 0;
            struct dirent *de;
            while((de = readdir(dirp)) != NULL)
            {
                // Add space for byte_size, user_id, group_id
                //  and props fields
                byte_count += 16;

                // Add space for name string
                byte_count += 2;
                byte_count += strlen(de->d_name);

                entry_count++;
            }
            rewinddir(dirp);

            // Allocate the buffer to send
            uint8_t *buf = (uint8_t *)malloc(byte_count);
//.........这里部分代码省略.........
开发者ID:MahmoudElShazly,项目名称:rpi-boot,代码行数:101,代码来源:raspbootin-server.c

示例14: listdir

static int listdir(const char *name, int flags)
{
    char tmp[4096];
    DIR *d;
    struct dirent *de;
    
    d = opendir(name);
    if(d == 0) {
        fprintf(stderr, "opendir failed, %s\n", strerror(errno));
        return -1;
    }

    while((de = readdir(d)) != 0){
        if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
        if(de->d_name[0] == '.' && (flags & LIST_ALL) == 0) continue;

        listfile(name, de->d_name, flags);
    }

    if (flags & LIST_RECURSIVE) {
        rewinddir(d);

        while ((de = readdir(d)) != 0) {
            struct stat s;
            int err;

            if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
                continue;
            if (de->d_name[0] == '.' && (flags & LIST_ALL) == 0)
                continue;

            if (!strcmp(name, "/"))
                snprintf(tmp, sizeof(tmp), "/%s", de->d_name);
            else
                snprintf(tmp, sizeof(tmp), "%s/%s", name, de->d_name);

            /*
             * If the name ends in a '/', use stat() so we treat it like a
             * directory even if it's a symlink.
             */
            if (tmp[strlen(tmp)-1] == '/')
                err = stat(tmp, &s);
            else
                err = lstat(tmp, &s);

            if (err < 0) {
                perror(tmp);
                closedir(d);
                return -1;
            }

            if (S_ISDIR(s.st_mode)) {
                printf("\n%s:\n", tmp);
                listdir(tmp, flags);
            }
        }
    }

    closedir(d);
    return 0;
}
开发者ID:SecretSemariten,项目名称:platform_system_core,代码行数:61,代码来源:ls.c

示例15: drive_file_query_directory

BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYTE InitialQuery,
	const char* path, wStream* output)
{
	int length;
	BOOL ret;
	WCHAR* ent_path;
	struct STAT st;
	struct dirent* ent;

	DEBUG_SVC("path %s FsInformationClass %d InitialQuery %d", path, FsInformationClass, InitialQuery);

	if (!file->dir)
	{
		Stream_Write_UINT32(output, 0); /* Length */
		Stream_Write_UINT8(output, 0); /* Padding */
		return FALSE;
	}

	if (InitialQuery != 0)
	{
		rewinddir(file->dir);
		free(file->pattern);

		if (path[0])
			file->pattern = _strdup(strrchr(path, '\\') + 1);
		else
			file->pattern = NULL;
	}

	if (file->pattern)
	{
		do
		{
			ent = readdir(file->dir);

			if (ent == NULL)
				continue;

			if (FilePatternMatchA(ent->d_name, file->pattern))
				break;

		}
		while (ent);
	}
	else
	{
		ent = readdir(file->dir);
	}

	if (ent == NULL)
	{
		DEBUG_SVC("  pattern %s not found.", file->pattern);
		Stream_Write_UINT32(output, 0); /* Length */
		Stream_Write_UINT8(output, 0); /* Padding */
		return FALSE;
	}

	memset(&st, 0, sizeof(struct STAT));
	ent_path = (WCHAR*) malloc(strlen(file->fullpath) + strlen(ent->d_name) + 2);
	sprintf((char*) ent_path, "%s/%s", file->fullpath, ent->d_name);

	if (STAT((char*) ent_path, &st) != 0)
	{
		DEBUG_WARN("stat %s failed. errno = %d", (char*) ent_path, errno);
	}

	DEBUG_SVC("  pattern %s matched %s", file->pattern, ent_path);
	free(ent_path);
	ent_path = NULL;

	length = ConvertToUnicode(CP_UTF8, 0, ent->d_name, -1, &ent_path, 0) * 2;

	ret = TRUE;

	switch (FsInformationClass)
	{
		case FileDirectoryInformation:
			/* http://msdn.microsoft.com/en-us/library/cc232097.aspx */
			Stream_Write_UINT32(output, 64 + length); /* Length */
			Stream_EnsureRemainingCapacity(output, 64 + length);
			Stream_Write_UINT32(output, 0); /* NextEntryOffset */
			Stream_Write_UINT32(output, 0); /* FileIndex */
			Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
			Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */
			Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */
			Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* ChangeTime */
			Stream_Write_UINT64(output, st.st_size); /* EndOfFile */
			Stream_Write_UINT64(output, st.st_size); /* AllocationSize */
			Stream_Write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
			Stream_Write_UINT32(output, length); /* FileNameLength */
			Stream_Write(output, ent_path, length);
			break;

		case FileFullDirectoryInformation:
			/* http://msdn.microsoft.com/en-us/library/cc232068.aspx */
			Stream_Write_UINT32(output, 68 + length); /* Length */
			Stream_EnsureRemainingCapacity(output, 68 + length);
			Stream_Write_UINT32(output, 0); /* NextEntryOffset */
			Stream_Write_UINT32(output, 0); /* FileIndex */
			Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
//.........这里部分代码省略.........
开发者ID:pevik,项目名称:debian-freerdp,代码行数:101,代码来源:drive_file.c


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