Re: [PATCH 2/4] Add functions get_relative_cwd() and is_inside_dir()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 1, 2007, 04:22 UTC
- Message-ID
- <7vy7gvdgtn.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <Pine.LNX.4.64.0708010129090.14781@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 16 quoted lines
> The function get_relative_cwd() works just as getcwd(), only that it
> takes an absolute path as additional parameter, returning the prefix
> of the current working directory relative to the given path. If the
> cwd is no subdirectory of the given path, it returns NULL.
> ...
> +/*
> + * get_relative_cwd() gets the prefix of the current working directory
> + * relative to 'dir'. If we are not inside 'dir', it returns NULL.
> + * As a convenience, it also returns NULL if 'dir' is already NULL.
> + */
> +char *get_relative_cwd(char *buffer, int size, const char *dir)
> +{
> + char *cwd = buffer;
> +
> + if (!dir || !getcwd(buffer, size))
> + return NULL;When is it not a fatal error if get_relative_cwd() is called with a NULL dir parameter, or getcwd() fails?
If there is no valid such cases, I would rather have this die(), former with "BUG" and the latter with strerror(errno).