示例#1
0
文件: path.c 项目: Mailaender/bam
/* return zero on success */
int path_join(const char *base, int base_len, const char *extend, int extend_len, char *output, int size)
{
	int i;
	if(extend_len < 0)
		extend_len = strlen(extend);
	
	if(path_isabs(extend))
	{
		/* just copy the extend path */
		if(extend_len+1 > size)
		{
			fprintf(stderr, "'%s' + '%s' results in a too long path\n", base, extend);
			return __LINE__;
		}
		
		memcpy(output, extend, extend_len+1);
		path_normalize(output);
		return 0;
	}
	
	if(base_len < 0)
		base_len = strlen(base);
	
	/* +2 for separator and null terminator */
	if(base_len+extend_len+2 > size)
	{
		fprintf(stderr, "'%s' + '%s' results in a too long path\n", base, extend);
		return __LINE__;
	}

	/* no base path, just use extend path then */
	if(base_len == 0)
	{
		memcpy(output, extend, extend_len+1);
		path_normalize(output);
		return 0;
	}
	
	/* copy base path */
	memcpy(output, base, base_len);
	
	/* append path separator if needed */
	if(!path_is_separator(base[base_len-1]))
	{
		output[base_len] = PATH_SEPARATOR;
		base_len++;
	}
	
	/* append the extra path, and null-terminator*/
	for(i = 0; i < extend_len+1; i++)
		output[base_len+i] = extend[i];
	
	/* normalize path and return success */
	path_normalize(output);
	return 0;
}
示例#2
0
int
path_absolute(const char* path, stralloc* sa) {
  int ret = 0;
  stralloc_zero(sa);

  if(!path_isabs(path)) {
    path_getcwd(sa);
    stralloc_catc(sa, PATHSEP_C);
    stralloc_cats(sa, path);
    return 1;
  }

  stralloc_copys(sa, path);
  return 0;
}
示例#3
0
文件: dep_cpp.c 项目: malind/bam
static int dependency_cpp_callback(struct NODE *node, void *user, const char *filename, int sys)
{
	struct CPPDEPINFO *depinfo = (struct CPPDEPINFO *)user;
	struct CPPDEPINFO recurseinfo;
	char buf[MAX_PATH_LENGTH];
	int check_system = sys;

	int found = 0;
	struct NODE *depnode = NULL;
	time_t timestamp = 0;
	
	
	if(!sys)
	{
		/* "normal.header" */
		int flen = strlen(node->filename)-1;
		while(flen)
		{
			if(node->filename[flen] == '/')
				break;
			flen--;
		}
		path_join(node->filename, flen, filename, -1, buf, sizeof(buf));
		
		if(node_findfile(node->graph, buf, &depnode, &timestamp))
			found = 1;
		else
		{
			/* file does not exist */
			check_system = 1;
		}
	}

	if(check_system)
	{
		/* <system.header> */
		if(path_isabs(filename))
		{
			if(node_findfile(node->graph, filename, &depnode, &timestamp))
			{
				strcpy(buf, filename);
				found = 1;
			}
		}
		else
		{
			struct STRINGLIST *cur;
			int flen = strlen(filename);

			for(cur = depinfo->paths; cur; cur = cur->next)
			{
				path_join(cur->str, cur->len, filename, flen, buf, sizeof(buf));
				if(node_findfile(node->graph, buf, &depnode, &timestamp))
				{
					found = 1;
					break;
				}
			}
		}
	}

	/* */
	if(found)
	{
		path_normalize(buf);
		if(!depnode)
			node_create(&depnode, node->graph, buf, NULL, timestamp);
		if(node_add_dependency (node, depnode) == NULL)
			return 2;

		if(!depnode)
			return 3;
	
		/* do the dependency walk */
		if(!depnode->depchecked)
		{
			recurseinfo.paths = depinfo->paths;
			recurseinfo.context = depinfo->context;
			if(dependency_cpp_run(depinfo->context, depnode, dependency_cpp_callback, &recurseinfo) != 0)
				return 4;
		}
	}
		
	return 0;
}