void add_default_cowpath(std::vector<std::string> &cowpath) { std::string path; if (!get_executable_directory(path)) return; add_cow_path_if_exists(cowpath, expanduser("~/.cows")); add_cow_path_if_exists(cowpath, expanduser("~/cows")); add_cow_path_if_exists(cowpath, path + "/../share/cows"); add_cow_path_if_exists(cowpath, path + "/../share/cows"); add_cow_path_if_exists(cowpath, "/usr/share/cows"); add_cow_path_if_exists(cowpath, "/usr/local/share/cows"); add_cow_path_if_exists(cowpath, path + "/cows"); }
void read_ignore_file() { FILE *fp; int i = 0; char *line = NULL; size_t len; int ret; /* ensure at least NULL is in the list */ ALLOC_GROW(ignore_patterns, 1, ignore_alloc); ignore_patterns[0] = NULL; if (!(fp = fopen(expanduser(IGNORE_FILE_NAME), "r"))) { if (errno == ENOENT) return; die_errno("fopen"); } while ((ret = getline(&line, &len, fp)) > 0) { i++; ALLOC_GROW(ignore_patterns, i+1, ignore_alloc); if (ret != strlen(line)) die("\\0 in ignore file"); if (line[ret-1] == '\n') line[ret-1] = '\0'; ignore_patterns[i-1] = line; line = NULL; } ignore_patterns[i] = NULL; if (fclose(fp) != 0) die_errno("fclose"); }
int main (int argc, char *argv[]) { int sock, conn; char *sockname; struct sockaddr_un addr, peer; socklen_t peer_sz; fd_set rfds; int ret; int maxfd; read_ignore_file(); ifd = inotify_init(); if (ifd < 0) die_errno("inotify_init"); setup_watches(expanduser("~")); setup_watches("/media"); sockname = expanduser(SOCKNAME); unlink(sockname); /* errors deliberately ignored */ sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) die_errno("socket"); memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)-1); if (bind(sock, (struct sockaddr *) &addr, sizeof(addr))) die_errno("bind"); if (listen(sock, 10)) die_errno("listen"); maxfd = sock; if (ifd > maxfd) maxfd = ifd; maxfd++; while (1) { FD_ZERO(&rfds); FD_SET(ifd, &rfds); FD_SET(sock, &rfds); ret = select(maxfd, &rfds, NULL, NULL, NULL); if (ret == -1) die_errno("select"); if (!ret) continue; if (FD_ISSET(ifd, &rfds)) handle_inotify(); if (FD_ISSET(sock, &rfds)) { conn = accept(sock, (struct sockaddr *) &peer, &peer_sz); if (conn < 0) die_errno("accept"); send_lru(conn); close(conn); /* errors ignored */ } } /* we never get here, but meh */ if (close(sock) < 0) die_errno("close"); return 0; }
std::string path::expand(const std::string &path) { return normpath(expandvars(expanduser(path))); }