Example #1
0
t_pad	ft_getpos(const char *format, char *to_free, int i, t_pad p)
{
	p.pos.max = -1;
	p.pos.min = 0;
	p.pos.zero = 0;
	p.opt = 0;
	get_lnum(format, i, &p.pos);
	get_lprec(format, i, &p.pos);
	p.pos.prec = ft_isheren(format, '.', i) > -1 ? 1 : 0;
	if (p.pos.prec == 1 && ft_atoi(format + p.pos.max) > 0)
		p.pos.prec = 2;
	else if (p.pos.prec == 1 && to_free[0] == '0' && (p.pos.type == 1))
		to_free[0] = '\0';
	if (p.pos.max > -1 && (format[i] == 'c' || format[i] == 'C'))
		p.pos.max = ft_atoi(format + p.pos.max) - 1;
	if (p.pos.max > -1 && (format[i] != 's' && format[i] != 'S'
		&& ((format[i] != 'd' && format[i] != 'i') || to_free[0] != '-')))
		p.pos.max = ft_atoi(format + p.pos.max) - ft_strlen(to_free);
	else if (p.pos.max > -1 && (format[i] == 'd' || format[i] == 'i')
		&& to_free[0] == '-')
		p.pos.max = ft_atoi(format + p.pos.max) - ft_strlen(to_free) + 1;
	else if (p.pos.max > -1 && (format[i] == 's' || format[i] == 'S'))
		p.pos.max = ft_atoi(format + p.pos.max);
	return (ft_getpos2(format, to_free, i, p));
}
Example #2
0
/*
 * Execute a file or path name w/ error handling.
 * This function never returns.
 */
void
err_pexec(const char *file, char *const *argv)
{
	long l;
	const char *f, *n;

	(void)pexec(file, argv);
#ifdef	DEBUG
	fd_print(FD2, "err_pexec: strerror(errno) == %s;\n", strerror(errno));
#endif

	f = (file == NULL) ? "(null)" : file;
	n = getmyname();

	if (EQUAL(n, "glob6")) {
		if (errno == ENOEXEC)
			err(SH_ERR, FMT1S, ERR_NOSHELL);
		if (errno == E2BIG)
			err(SH_ERR, FMT1S, ERR_E2BIG);
		err(SH_ERR, FMT1S, ERR_GNOTFOUND);
	} else if (EQUAL(n, "sh6")) {
		if (errno == ENOEXEC)
			err(125, FMT1S, ERR_NOSHELL);
		if (errno == E2BIG)
			err(126, FMT2S, f, ERR_E2BIG);
		if (errno != ENOENT && errno != ENOTDIR)
			err(126, FMT2S, f, ERR_EXEC);
		err(127, FMT2S, f, ERR_NOTFOUND);
	} else {
		l = no_lnum ? -1 : get_lnum();
		if (name != NULL) {
			if (l != -1) {
				if (errno == ENOEXEC)
					err(125,FMT4LS,n,name,l,f, ERR_NOSHELL);
				if (errno == E2BIG)
					err(126,FMT4LS,n,name, l, f, ERR_E2BIG);
				if (errno != ENOENT && errno != ENOTDIR)
					err(126,FMT4LS,n, name, l, f, ERR_EXEC);
				err(127, FMT4LS, n, name, l, f, ERR_NOTFOUND);
			} else {
				if (errno == ENOEXEC)
					err(125,FMT4S, n, name, f, ERR_NOSHELL);
				if (errno == E2BIG)
					err(126, FMT4S, n, name, f, ERR_E2BIG);
				if (errno != ENOENT && errno != ENOTDIR)
					err(126, FMT4S, n, name, f, ERR_EXEC);
				err(127, FMT4S, n, name, f, ERR_NOTFOUND);
			}
		} else {
			if (l != -1) {
				if (errno == ENOEXEC)
					err(125, FMT3LFS, n, l, f, ERR_NOSHELL);
				if (errno == E2BIG)
					err(126, FMT3LFS, n, l, f, ERR_E2BIG);
				if (errno != ENOENT && errno != ENOTDIR)
					err(126, FMT3LFS, n, l, f, ERR_EXEC);
				err(127, FMT3LFS, n, l, f, ERR_NOTFOUND);
			} else {
				if (errno == ENOEXEC)
					err(125, FMT3S, n, f, ERR_NOSHELL);
				if (errno == E2BIG)
					err(126, FMT3S, n, f, ERR_E2BIG);
				if (errno != ENOENT && errno != ENOTDIR)
					err(126, FMT3S, n, f, ERR_EXEC);
				err(127, FMT3S, n, f, ERR_NOTFOUND);
			}
		}
	}
}