stats.c
char *cmd_cwd(char *cmd)
{
	unsigned int i, bi, size = 120;
	struct stat st;
	char *buf = malloc(sizeof(char) * size);

	if (!cmd || !buf)
		return (NULL);
/* put working directory in buffer & while buf is too small, free and */
/*  allocate double before doing it again */
	while (getcwd(buf, size) == NULL)
	{
		size *= 2, free(buf);
		buf = malloc(sizeof(char) * size);
		if (!buf)
			return (NULL);
	}
/* start buffer index at end of directory name */
	bi = _strlen(buf);
	if (cmd[0] != '/')
		buf[bi++] = '/';
/* write the arguments into the buffer to get full path */
	for (i = 0; cmd[i]; i++, bi++)
	{
		if (bi + 1 > size)
		{
/* reallocate if buf is too small to add cmd */
			buf = _reallocf(buf, size, size * 2), size *= 2;
			if (!buf)
				return (NULL);
		}
		buf[bi] = cmd[i];
	}
	buf[bi] = 00;
	if (stat(buf, &st) == 0)
		return (buf);
	free(buf);
	return (NULL);
}
/**
 * cmd_cwd - appends the cmd string to the current directory if found there
 * @cmd: first string of command
 * Return: string starting with cwd and ending with the cmd if found there,
 * else NULL
 */
appends the cmd string to the current directory if found there
@cmd: first string of command
Return: string starting with cwd and ending with the cmd if found there,
else NULL
appends the cmd string to the current directory if found there @cmd : first string of command Return : string starting with cwd and ending with the cmd if found there else NULL
char *cmd_cwd(char *cmd)
{
	unsigned int i, bi, size = 120;
	struct stat st;
	char *buf = malloc(sizeof(char) * size);
	if (!cmd || !buf)
		return (NULL);
	while (getcwd(buf, size) == NULL)
	{
		size *= 2, free(buf);
		buf = malloc(sizeof(char) * size);
		if (!buf)
			return (NULL);
	}
	bi = _strlen(buf);
	if (cmd[0] != '/')
		buf[bi++] = '/';
	for (i = 0; cmd[i]; i++, bi++)
	{
		if (bi + 1 > size)
		{
			buf = _reallocf(buf, size, size * 2), size *= 2;
			if (!buf)
				return (NULL);
		}
		buf[bi] = cmd[i];
	}
	buf[bi] = 00;
	if (stat(buf, &st) == 0)
		return (buf);
	free(buf);
	return (NULL);
}
char * cmd_cwd ( char * cmd ) { unsigned int i , bi , size = 120 ; struct stat st ; char * buf = malloc ( sizeof ( char ) * size ) ; if ( ! cmd || ! buf ) return ( NULL ) ; while ( getcwd ( buf , size ) == NULL ) { size *= 2 , free ( buf ) ; buf = malloc ( sizeof ( char ) * size ) ; if ( ! buf ) return ( NULL ) ; } bi = _strlen ( buf ) ; if ( cmd [ 0 ] != ' ' ) buf [ bi ++ ] = ' ' ; for ( i = 0 ; cmd [ i ] ; i ++ , bi ++ ) { if ( bi + 1 > size ) { buf = _reallocf ( buf , size , size * 2 ) , size *= 2 ; if ( ! buf ) return ( NULL ) ; } buf [ bi ] = cmd [ i ] ; } buf [ bi ] = 00 ; if ( stat ( buf , & st ) == 0 ) return ( buf ) ; free ( buf ) ; return ( NULL ) ; }
cmd_cwd - appends the cmd string to the current directory if found there
 @cmd: first string of command
 Return: string starting with cwd and ending with the cmd if found there,
 else NULL
cmd_cwd - appends the cmd string to the current directory if found there @cmd : first string of command Return : string starting with cwd and ending with the cmd if found there else NULL
/* put working directory in buffer & while buf is too small, free and */ /*  allocate double before doing it again */ /* start buffer index at end of directory name */ /* write the arguments into the buffer to get full path */ /* reallocate if buf is too small to add cmd */