示例#1
0
gchar *tm_get_real_path(const gchar *file_name)
{
	if (file_name)
	{
		gsize len = get_path_max(file_name) + 1;
		gchar *path = g_malloc0(len);

		if (realpath(file_name, path))
			return path;
		else
			g_free(path);
	}
	return NULL;
}
示例#2
0
/* realpath implementation for Windows found at http://bugzilla.gnome.org/show_bug.cgi?id=342926
 * this one is better than e.g. liberty's lrealpath because this one uses Win32 API and works
 * with special chars within the filename */
static char *realpath (const char *pathname, char *resolved_path)
{
  int size;

  if (resolved_path != NULL)
  {
    int path_max = get_path_max(pathname);
	size = GetFullPathNameA (pathname, path_max, resolved_path, NULL);
    if (size > path_max)
      return NULL;
    else
      return resolved_path;
  }
  else
  {
    size = GetFullPathNameA (pathname, 0, NULL, NULL);
    resolved_path = g_new0 (char, size);
    GetFullPathNameA (pathname, size, resolved_path, NULL);
    return resolved_path;
  }
}
示例#3
0
/** get_fullpath
 * Gets the fullpath name of a file
 * 
 * Parameters:
 *     struct Filename *file - the names associated with the file
 *     struct char **memptr - the location to store the fullpath name
 *     struct Globals *gl - the "global" variables for this search
 * Return Value:
 *     char* - returns the fullpath name
 */
void
get_fullpath(struct Filename *file, char **memptr, struct Globals *gl){
	if((gl->path_max) == DEFAULT_PATH_MAX)
		get_path_max(file->name, &(gl->path_max));
		
	*memptr = malloc((gl->path_max));
	if(*memptr == NULL){
		/* If memory allocation failed, print an error */
		if(file->is_cmd_line || (gl->my_flags&QUIET) != QUIET){
			/* If the file was specified on the commandline or if the -q flag 
			   was not selected then print the error */
			pthread_mutex_lock(&mu);
			if(gl->is_network){
				char *output;
			
				output = calloc(sizeof(char), gl->path_max);
				sprintf(output, "%14s: %s %s\n", "malloc()", strerror(errno), file->name);
				write_error_line(output, gl);
				free(output);
			}
			fprintf(stderr, "%14s: %s %s\n", "malloc()", strerror(errno), file->name);
			pthread_mutex_unlock(&mu);
		}
		else{
			/* If the file error was not printed then increment the 
			   corresponding counter */
			file->counters->err_not_printed++;
		}
		return;
	}
	
	strcpy(*memptr, file->realptr);
	strcat(*memptr, "/");
	strcat(*memptr, file->name);
	/*get_fullpath*/
}
示例#4
0
/** get_realpath
 * Gets the realpath name of a file
 * 
 * Parameters:
 *     struct Filename *file - the names associated with the file
 *     char **realptr - the real name of the file
 *     struct Globals *gl - the "global" variables for this search
 * Return Value:
 *     char* - returns the realpath name
 */
void 
get_realpath(struct Filename *file, char **realptr, struct Globals *gl){
	char *memptr;
	
	unsigned int my_flags;
	int path_max;
	my_flags = gl->my_flags;
	path_max = gl->path_max;
	
	if(path_max == DEFAULT_PATH_MAX)
		get_path_max(file->name, &(gl->path_max));
		
	memptr = malloc(path_max);
	if(memptr == NULL){
		/* If memory allocation failed, print an error */
		if(file->is_cmd_line || (my_flags&QUIET) != QUIET){
			/* If the file was specified on the commandline or if the -q flag 
			   was not selected then print the error */
			pthread_mutex_lock(&mu);
			if(file->is_cmd_line){
				if(gl->is_network){
					char *output;
					
					output = calloc(sizeof(char), gl->path_max);
					sprintf(output, "%14s: %s %s\n", "malloc()", strerror(errno), file->name);
					write_error_line(output, gl);
					free(output);
				}
				fprintf(stderr, "%14s: %s %s\n", "malloc()", strerror(errno), file->name);
			}else{
				if(gl->is_network){
					char *output;
					
					output = calloc(sizeof(char), gl->path_max);
					sprintf(output, "%14s: %s %s\n", "malloc()", strerror(errno), file->fullptr);
					write_error_line(output, gl);
					free(output);
				}
				fprintf(stderr, "%14s: %s %s\n", "malloc()", strerror(errno), file->fullptr);
			}
			pthread_mutex_unlock(&mu);
		}
		else{
			/* If the file error was not printed then increment the 
			   corresponding counter */
			file->counters->err_not_printed++;
		}
		return;
	}else{
		/* Otherwise set the realpath name to the realptr */
		if(file->is_cmd_line)
			*realptr = realpath(file->name, memptr);
		else
			*realptr = realpath(file->fullptr, memptr);
		if(*realptr == NULL){
			/* If the realpath name is NULL then an error occurred */
			if(file->is_cmd_line || (my_flags&QUIET) != QUIET){
				/* If the file was specified on the commandline or if the -q flag 
			       was not selected then print the error */
				pthread_mutex_lock(&mu);
				if(file->is_cmd_line){
					if(gl->is_network){
						char *output;
					
						output = calloc(sizeof(char), gl->path_max);
						sprintf(output, "%s: %s\n", strerror(errno), file->name);
						write_error_line(output, gl);
						free(output);
					}
					fprintf(stderr, "%s: %s\n", strerror(errno), file->name);
				}
				else{
					if(gl->is_network){
						char *output;
					
						output = calloc(sizeof(char), gl->path_max);
						sprintf(output, "%s: %s\n", strerror(errno), file->fullptr);
						write_error_line(output, gl);
						free(output);
					}
					fprintf(stderr, "%s: %s\n", strerror(errno), file->fullptr);
				}
				pthread_mutex_unlock(&mu);
			}
			else{
				/* If the file error was not printed then increment the 
			       corresponding counter */
				file->counters->err_not_printed++;
			}
			return;
		}
	}
	/*get_realpath*/
}