+/* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least
+ * DEFAULT_TEXT_BUFFER_SIZE. It's similar to variable_substitute, except only
+ * cheques for $HOME and ~/ in path */
+void to_real_path(char *dest, const char *source)
+{
+ char tmp[DEFAULT_TEXT_BUFFER_SIZE];
+ if (sscanf(source, "~/%s", tmp) || sscanf(source, "$HOME/%s", tmp)) {
+ char *homedir = getenv("HOME");
+ if (homedir) {
+ snprintf(dest, DEFAULT_TEXT_BUFFER_SIZE, "%s/%s", homedir, tmp);
+ } else {
+ NORM_ERR("$HOME environment variable doesn't exist");
+ strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
+ }
+ } else if (dest != source) { //see changelog 2009-06-29 if you doubt that this check is necessary
+ strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
+ }
+}
+
+int open_fifo(const char *file, int *reported)
+{
+ char path[DEFAULT_TEXT_BUFFER_SIZE];
+ int fd = 0;
+
+ to_real_path(path, file);
+ fd = open(file, O_RDONLY | O_NONBLOCK);
+
+ if (fd == -1) {
+ if (!reported || *reported == 0) {
+ NORM_ERR("can't open %s: %s", file, strerror(errno));
+ if (reported) {
+ *reported = 1;
+ }
+ }
+ return -1;
+ }
+
+ return fd;
+}
+