/* vi: set sw=4 ts=4 :*/
/* lib.c - reusable stuff.
 *
 * Functions with the x prefix are wrappers for library functions.  They either
 * succeed or kill the program with an error message, but never return failure.
 * They usually have the same arguments and return value as the function they
 * wrap.
 *
 * Copyright 2006 Rob Landley <rob@landley.net>
 */

#include "toys.h"

// Strcpy with size checking: exit if there's not enough space for the string.
void xstrcpy(char *dest, char *src, size_t size)
{
	if (strlen(src)+1 > size) error_exit("xstrcpy");
	strcpy(dest, src);
}

void verror_msg(char *msg, int err, va_list va)
{
	char *s = ": %s";

	fprintf(stderr, "%s: ", toys.which->name);
	if (msg) vfprintf(stderr, msg, va);
	else s+=2;
	if (err) fprintf(stderr, s, strerror(err));
	putc('\n', stderr);
}

void error_msg(char *msg, ...)
{
	va_list va;

	va_start(va, msg);
	verror_msg(msg, 0, va);
	va_end(va);
}

void perror_msg(char *msg, ...)
{
	va_list va;

	va_start(va, msg);
	verror_msg(msg, errno, va);
	va_end(va);
}

// Die with an error message.
void error_exit(char *msg, ...)
{
	va_list va;

	if (CFG_HELP && toys.exithelp) {
		*toys.optargs=*toys.argv;
		USE_HELP(help_main();)  // dear gcc: shut up.
		fprintf(stderr,"\n");
	}

	va_start(va, msg);
	verror_msg(msg, 0, va);
	va_end(va);

	exit(!toys.exitval ? 1 : toys.exitval);
}


// Die with an error message and strerror(errno)
void perror_exit(char *msg, ...)
{
	va_list va;

	va_start(va, msg);
	verror_msg(msg, errno, va);
	va_end(va);

	exit(!toys.exitval ? 1 : toys.exitval);
}

// Die unless we can allocate memory.
void *xmalloc(size_t size)
{
	void *ret = malloc(size);
	if (!ret) error_exit("xmalloc");

	return ret;
}

// Die unless we can allocate prezeroed memory.
void *xzalloc(size_t size)
{
	void *ret = xmalloc(size);
	memset(ret, 0, size);
	return ret;
}

// Die unless we can change the size of an existing allocation, possibly
// moving it.  (Notice different arguments from libc function.)
void *xrealloc(void *ptr, size_t size)
{
	ptr = realloc(ptr, size);
	if (!ptr) error_exit("xrealloc");

	return ptr;
}

// Die unless we can allocate a copy of this many bytes of string.
char *xstrndup(char *s, size_t n)
{
	char *ret = xmalloc(++n);
	strncpy(ret, s, n);
	ret[--n]=0;

	return ret;
}

// Die unless we can allocate a copy of this string.
char *xstrdup(char *s)
{
	return xstrndup(s, strlen(s));
}

// Die unless we can allocate enough space to sprintf() into.
char *xmsprintf(char *format, ...)
{
	va_list va, va2;
	int len;
	char *ret;

	va_start(va, format);
	va_copy(va2, va);

	// How long is it?
	len = vsnprintf(0, 0, format, va);
	len++;
	va_end(va);

	// Allocate and do the sprintf()
	ret = xmalloc(len);
	vsnprintf(ret, len, format, va2);
	va_end(va2);

	return ret;
}

void xprintf(char *format, ...)
{
	va_list va;
	va_start(va, format);

	vprintf(format, va);
	if (ferror(stdout)) perror_exit("write");
}

void xputs(char *s)
{
	if (EOF == puts(s)) perror_exit("write");
}

void xputc(char c)
{
	if (EOF == fputc(c, stdout)) perror_exit("write");
}

void xflush(void)
{
	if (fflush(stdout)) perror_exit("write");;
}

// Die unless we can exec argv[] (or run builtin command).  Note that anything
// with a path isn't a builtin, so /bin/sh won't match the builtin sh.
void xexec(char **argv)
{
	toy_exec(argv);
	execvp(argv[0], argv);

	perror_exit("exec %s", argv[0]);
}

void xaccess(char *path, int flags)
{
	if (access(path, flags)) perror_exit("Can't access '%s'", path);
}

// Die unless we can delete a file.  (File must exist to be deleted.)
void xunlink(char *path)
{
	if (unlink(path)) perror_exit("unlink '%s'", path);
}

// Die unless we can open/create a file, returning file descriptor.
int xcreate(char *path, int flags, int mode)
{
	int fd = open(path, flags, mode);
	if (fd == -1) perror_exit("%s", path);
	return fd;
}

// Die unless we can open a file, returning file descriptor.
int xopen(char *path, int flags)
{
	return xcreate(path, flags, 0);
}

void xclose(int fd)
{
	if (close(fd)) perror_exit("xclose");
}

// Die unless we can open/create a file, returning FILE *.
FILE *xfopen(char *path, char *mode)
{
	FILE *f = fopen(path, mode);
	if (!f) perror_exit("No file %s", path);
	return f;
}

// Keep reading until full or EOF
ssize_t readall(int fd, void *buf, size_t len)
{
	size_t count = 0;

	while (count<len) {
		int i = read(fd, buf+count, len-count);
		if (!i) break;
		if (i<0) return i;
		count += i;
	}

	return count;
}

// Keep writing until done or EOF
ssize_t writeall(int fd, void *buf, size_t len)
{
	size_t count = 0;
	while (count<len) {
		int i = write(fd, buf+count, len-count);
		if (i<1) return i;
		count += i;
	}

	return count;
}

// Die if there's an error other than EOF.
size_t xread(int fd, void *buf, size_t len)
{
	ssize_t ret = read(fd, buf, len);
	if (ret < 0) perror_exit("xread");

	return ret;
}

void xreadall(int fd, void *buf, size_t len)
{
	if (len != readall(fd, buf, len)) perror_exit("xreadall");
}

// There's no xwriteall(), just xwrite().  When we read, there may or may not
// be more data waiting.  When we write, there is data and it had better go
// somewhere.

void xwrite(int fd, void *buf, size_t len)
{
	if (len != writeall(fd, buf, len)) perror_exit("xwrite");
}

// Die if lseek fails, probably due to being called on a pipe.

off_t xlseek(int fd, off_t offset, int whence)
{
	offset = lseek(fd, offset, whence);
	if (offset<0) perror_exit("lseek");

	return offset;
}

char *xgetcwd(void)
{
	char *buf = getcwd(NULL, 0);
	if (!buf) perror_exit("xgetcwd");

	return buf;
}

void xstat(char *path, struct stat *st)
{
	if(stat(path, st)) perror_exit("Can't stat %s", path);
}

// Cannonicalizes path by removing ".", "..", and "//" elements.  This is not
// the same as realpath(), where "dir/.." could wind up somewhere else by
// following symlinks.
char *xabspath(char *path)
{
	char *from, *to;

	// If this isn't an absolute path, make it one with cwd.
	if (path[0]!='/') {
		char *cwd=xgetcwd();
		path = xmsprintf("%s/%s", cwd, path);
		free(cwd);
	} else path = xstrdup(path);

	// Loop through path elements
	from = to = path;
	while (*from) {

		// Continue any current path component.
		if (*from!='/') {
			*(to++) = *(from++);
			continue;
		}

		// Skip duplicate slashes.
		while (*from=='/') from++;

		// Start of a new filename.  Handle . and ..
		while (*from=='.') {
			// Skip .
			if (from[1]=='/') from += 2;
			else if (!from[1]) from++;
			// Back up for ..
			else if (from[1]=='.') {
				if (from[2]=='/') from +=3;
				else if(!from[2]) from+=2;
				else break;
				while (to>path && *(--to)!='/');
			} else break;
		}
		// Add directory separator slash.
		*(to++) = '/';
	}
	*to = 0;

	return path;
}

void xchdir(char *path)
{
	if (chdir(path)) error_exit("chdir '%s'", path);
}

// Ensure entire path exists.
// If mode != -1 set permissions on newly created dirs.
// Requires that path string be writable (for temporary null terminators).
void xmkpath(char *path, int mode)
{
	char *p, old;
	mode_t mask;
	int rc;
	struct stat st;

	for (p = path; ; p++) {
		if (!*p || *p == '/') {
			old = *p;
			*p = rc = 0;
			if (stat(path, &st) || !S_ISDIR(st.st_mode)) {
				if (mode != -1) {
					mask=umask(0);
					rc = mkdir(path, mode);
					umask(mask);
				} else rc = mkdir(path, 0777);
			}
			*p = old;
			if(rc) perror_exit("mkpath '%s'", path);
		}
		if (!*p) break;
	}
}

// setuid() can fail (for example, too many processes belonging to that user),
// which opens a security hole if the process continues as the original user.

void xsetuid(uid_t uid)
{
	if (setuid(uid)) perror_exit("xsetuid");
}


// Find all file in a colon-separated path with access type "type" (generally
// X_OK or R_OK).  Returns a list of absolute paths to each file found, in
// order.

struct string_list *find_in_path(char *path, char *filename)
{
	struct string_list *rlist = NULL, **prlist=&rlist;
	char *cwd = xgetcwd();

	for (;;) {
		char *next = path ? index(path, ':') : NULL;
		int len = next ? next-path : strlen(path);
		struct string_list *rnext;
		struct stat st;

		rnext = xmalloc(sizeof(void *) + strlen(filename)
			+ (len ? len : strlen(cwd)) + 2);
		if (!len) sprintf(rnext->str, "%s/%s", cwd, filename);
		else {
			char *res = rnext->str;
			strncpy(res, path, len);
			res += len;
			*(res++) = '/';
			strcpy(res, filename);
		}

		// Confirm it's not a directory.
		if (!stat(rnext->str, &st) && S_ISREG(st.st_mode)) {
			*prlist = rnext;
			rnext->next = NULL;
			prlist = &(rnext->next);
		} else free(rnext);

		if (!next) break;
		path += len;
		path++;
	}
	free(cwd);

	return rlist;
}

// Convert unsigned int to ascii, writing into supplied buffer.  A truncated
// result contains the first few digits of the result ala strncpy, and is
// always null terminated (unless buflen is 0).
void utoa_to_buf(unsigned n, char *buf, unsigned buflen)
{
	int i, out = 0;

	if (buflen) {
		for (i=1000000000; i; i/=10) {
			int res = n/i;

			if ((res || out || i == 1) && --buflen>0) {
				out++;
				n -= res*i;
				*buf++ = '0' + res;
			}
		}
		*buf = 0;
	}
}

// Convert signed integer to ascii, using utoa_to_buf()
void itoa_to_buf(int n, char *buf, unsigned buflen)
{
	if (buflen && n<0) {
		n = -n;
		*buf++ = '-';
		buflen--;
	}
	utoa_to_buf((unsigned)n, buf, buflen);
}

// This static buffer is used by both utoa() and itoa(), calling either one a
// second time will overwrite the previous results.
//
// The longest 32 bit integer is -2 billion plus a null terminator: 12 bytes.
// Note that int is always 32 bits on any remotely unix-like system, see
// http://www.unix.org/whitepapers/64bit.html for details.

static char itoa_buf[12];

// Convert unsigned integer to ascii, returning a static buffer.
char *utoa(unsigned n)
{
	utoa_to_buf(n, itoa_buf, sizeof(itoa_buf));

	return itoa_buf;
}

char *itoa(int n)
{
	itoa_to_buf(n, itoa_buf, sizeof(itoa_buf));

	return itoa_buf;
}

// atol() with the kilo/mega/giga/tera/peta/exa extensions.
// (zetta and yotta don't fit in 64 bits.)
long atolx(char *numstr)
{
	char *c, *suffixes="kmgtpe", *end;
	long val = strtol(numstr, &c, 0);

	if (*c) {
		end = strchr(suffixes, tolower(*c));
		if (end) val *= 1024L<<((end-suffixes)*10);
		else {
			while (isspace(*c)) c++;
			if (*c) error_exit("not integer: %s", numstr);
		}
	}

	return val;
}

// Return how long the file at fd is, if there's any way to determine it.
off_t fdlength(int fd)
{
	off_t bottom = 0, top = 0, pos, old;
	int size;

	// If the ioctl works for this, return it.

	if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512L;

	// If not, do a binary search for the last location we can read.  (Some
	// block devices don't do BLKGETSIZE right.)  This should probably have
	// a CONFIG option...

	old = lseek(fd, 0, SEEK_CUR);
	do {
		char temp;

		pos = bottom + (top - bottom) / 2;

		// If we can read from the current location, it's bigger.

		if (lseek(fd, pos, 0)>=0 && read(fd, &temp, 1)==1) {
			if (bottom == top) bottom = top = (top+1) * 2;
			else bottom = pos;

			// If we can't, it's smaller.

		} else {
			if (bottom == top) {
				if (!top) return 0;
				bottom = top/2;
			} else top = pos;
		}
	} while (bottom + 1 != top);

	lseek(fd, old, SEEK_SET);

	return pos + 1;
}

// This can return null (meaning file not found).  It just won't return null
// for memory allocation reasons.
char *xreadlink(char *name)
{
	int len, size = 0;
	char *buf = 0;

	// Grow by 64 byte chunks until it's big enough.
	for(;;) {
		size +=64;
		buf = xrealloc(buf, size);
		len = readlink(name, buf, size);

		if (len<0) {
			free(buf);
			return 0;
		}
		if (len<size) {
			buf[len]=0;
			return buf;
		}
	}
}

/*
 This might be of use or might not.  Unknown yet...

// Read contents of file as a single freshly allocated nul-terminated string.
char *readfile(char *name)
{
	off_t len;
	int fd;
	char *buf;

	fd = open(name, O_RDONLY);
	if (fd == -1) return 0;
	len = fdlength(fd);
	buf = xmalloc(len+1);
	buf[readall(fd, buf, len)] = 0;

	return buf;
}

char *xreadfile(char *name)
{
	char *buf = readfile(name);
	if (!buf) perror_exit("xreadfile %s", name);
	return buf;
}

*/

// Open a /var/run/NAME.pid file, dying if we can't write it or if it currently
// exists and is this executable.
void xpidfile(char *name)
{
	char pidfile[256], spid[32];
	int i, fd;
	pid_t pid;
	
	sprintf(pidfile, "/var/run/%s.pid", name);
	// Try three times to open the sucker.
	for (i=0; i<3; i++) {
		fd = open(pidfile, O_CREAT|O_EXCL, 0644);
		if (fd != -1) break;

		// If it already existed, read it.  Loop for race condition.
		fd = open(pidfile, O_RDONLY);
		if (fd == -1) continue;

		// Is the old program still there?
		spid[xread(fd, spid, sizeof(spid)-1)] = 0;
		close(fd);
		pid = atoi(spid);
		if (fd < 1 || kill(pid, 0) == ESRCH) unlink(pidfile);

		// An else with more sanity checking might be nice here.
	}

	if (i == 3) error_exit("xpidfile %s", name);

	xwrite(fd, spid, sprintf(spid, "%ld\n", (long)getpid()));
	close(fd);
}

// Iterate through an array of files, opening each one and calling a function
// on that filehandle and name.  The special filename "-" means stdin if
// flags is O_RDONLY, stdout otherwise.  An empty argument list calls
// function() on just stdin/stdout.
//
// Note: read only filehandles are automatically closed when function()
// returns, but writeable filehandles must be close by function()
void loopfiles_rw(char **argv, int flags, int permissions, int failok,
	void (*function)(int fd, char *name))
{
	int fd;

	// If no arguments, read from stdin.
	if (!*argv) function(flags ? 1 : 0, "-");
	else do {
		// Filename "-" means read from stdin.
		// Inability to open a file prints a warning, but doesn't exit.

		if (!strcmp(*argv,"-")) fd=0;
		else if (0>(fd = open(*argv, flags, permissions)) && !failok) {
			perror_msg("%s", *argv);
			toys.exitval = 1;
			continue;
		}
		function(fd, *argv);
		if (!flags) close(fd);
	} while (*++argv);
}

// Call loopfiles_rw with O_RDONLY and !failok (common case).
void loopfiles(char **argv, void (*function)(int fd, char *name))
{
	loopfiles_rw(argv, O_RDONLY, 0, 0, function);
}

// Slow, but small.

char *get_rawline(int fd, long *plen, char end)
{
	char c, *buf = NULL;
	long len = 0;

	for (;;) {
		if (1>read(fd, &c, 1)) break;
		if (!(len & 63)) buf=xrealloc(buf, len+65);
		if ((buf[len++]=c) == end) break;
	}
	if (buf) buf[len]=0;
	if (plen) *plen = len;

	return buf;
}

char *get_line(int fd)
{
	long len;
	char *buf = get_rawline(fd, &len, '\n');

	if (buf && buf[--len]=='\n') buf[len]=0;

	return buf;
}

// Copy the rest of in to out and close both files.

void xsendfile(int in, int out)
{
	long len;
	char buf[4096];

	if (in<0) return;
	for (;;) {
		len = xread(in, buf, 4096);
		if (len<1) break;
		xwrite(out, buf, len);
	}
}

// Open a temporary file to copy an existing file into.
int copy_tempfile(int fdin, char *name, char **tempname)
{
	struct stat statbuf;
	int fd;

	*tempname = xstrndup(name, strlen(name)+6);
	strcat(*tempname,"XXXXXX");
	if(-1 == (fd = mkstemp(*tempname))) error_exit("no temp file");

	// Set permissions of output file

	fstat(fdin, &statbuf);
	fchmod(fd, statbuf.st_mode);

	return fd;
}

// Abort the copy and delete the temporary file.
void delete_tempfile(int fdin, int fdout, char **tempname)
{
	close(fdin);
	close(fdout);
	unlink(*tempname);
	free(*tempname);
	*tempname = NULL;
}

// Copy the rest of the data and replace the original with the copy.
void replace_tempfile(int fdin, int fdout, char **tempname)
{
	char *temp = xstrdup(*tempname);

	temp[strlen(temp)-6]=0;
	if (fdin != -1) {
		xsendfile(fdin, fdout);
		xclose(fdin);
	}
	xclose(fdout);
	rename(*tempname, temp);
	free(*tempname);
	free(temp);
	*tempname = NULL;
}

// Create a 256 entry CRC32 lookup table.

void crc_init(unsigned int *crc_table, int little_endian)
{
	unsigned int i;

	// Init the CRC32 table (big endian)
	for (i=0; i<256; i++) {
		unsigned int j, c = little_endian ? i : i<<24;
		for (j=8; j; j--)
			if (little_endian) c = (c&1) ? (c>>1)^0xEDB88320 : c>>1;
			else c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
		crc_table[i] = c;
	}
}

// Quick and dirty query size of terminal, doesn't do ANSI probe fallback.
// set *x=0 and *y=0 before calling to detect failure to set either, or
// x=80 y=25 to provide defaults

void terminal_size(unsigned *x, unsigned *y)
{
	struct winsize ws;
	int i;

	//memset(&ws, 0, sizeof(ws));
	for (i=0; i<3; i++) {
		if (ioctl(i, TIOCGWINSZ, &ws)) continue;
		if (x) *x = ws.ws_col;
		if (y) *y = ws.ws_row;
	}
	if (x) {
		char *s = getenv("COLUMNS");

		i = s ? atoi(s) : 0;
		if (i>0) *x = i;
	}
	if (y) {
		char *s = getenv("ROWS");

		i = s ? atoi(s) : 0;
		if (i>0) *y = i;
	}
}

// This should use a raw tty, fixit later.
int yesno(int def)
{
	char buf[16];
	int i;

	for (i=0; i<3 && !isatty(i); i++);
	if (i == 3) return 1;

	sprintf(buf, "(%c/%c):", def ? 'Y' : 'y', def ? 'n' : 'N');
	write(i, buf, 6);
	while (read(i, buf, 1)) {
		if (isspace(*buf)) break;
		if (tolower(*buf) == 'y') return 1;
		if (tolower(*buf) == 'n') return 0;
	}
	return def;
}

// Execute a callback for each PID that matches a process name from a list.
void for_each_pid_with_name_in(char **names, void (*callback)(pid_t pid))
{
    DIR *dp;
    struct dirent *entry;
    char cmd[PATH_MAX], path[64];
    char **curname;

    if (!(dp = opendir("/proc"))) perror_exit("opendir");

    while ((entry = readdir(dp))) {
        int fd;

        if (!isdigit(*entry->d_name)) continue;

        if (sizeof(path) <= snprintf(path, sizeof(path), "/proc/%s/cmdline", 
            entry->d_name)) continue;

        if (-1 != (fd=xopen(path, O_RDONLY))) {
            int n = read(fd, cmd, sizeof(cmd));

            close(fd);
            if (n<1) continue;

            for (curname = names; *curname; curname++)
                if (!strcmp(basename(cmd), *curname))
                    callback(atol(entry->d_name));
        }
    }

    closedir(dp);
}
