Przeglądaj źródła

libdpkg: Add new file_show() function

Guillem Jover 14 lat temu
rodzic
commit
025669285a
3 zmienionych plików z 28 dodań i 1 usunięć
  1. 26 1
      lib/dpkg/file.c
  2. 1 0
      lib/dpkg/file.h
  3. 1 0
      lib/dpkg/libdpkg.map

+ 26 - 1
lib/dpkg/file.c

@@ -3,7 +3,7 @@
  * file.c - file handling functions
  *
  * Copyright © 1994, 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright © 2008 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,6 +32,8 @@
 
 #include <dpkg/dpkg.h>
 #include <dpkg/i18n.h>
+#include <dpkg/subproc.h>
+#include <dpkg/command.h>
 #include <dpkg/file.h>
 
 /**
@@ -150,3 +152,26 @@ file_lock(int *lockfd, enum file_lock_flags flags, const char *filename,
 
 	push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 2, lockfd, desc);
 }
+
+void
+file_show(const char *filename)
+{
+	pid_t pid;
+
+	if (filename == NULL)
+		internerr("file '%s' does not exist", filename);
+
+	pid = subproc_fork();
+	if (pid == 0) {
+		struct command cmd;
+		const char *pager;
+
+		pager = command_get_pager();
+
+		command_init(&cmd, pager, _("showing file on pager"));
+		command_add_arg(&cmd, pager);
+		command_add_arg(&cmd, filename);
+		command_exec(&cmd);
+	}
+	subproc_wait(pid, _("showing file on pager"));
+}

+ 1 - 0
lib/dpkg/file.h

@@ -52,6 +52,7 @@ bool file_is_locked(int lockfd, const char *filename);
 void file_lock(int *lockfd, enum file_lock_flags flags, const char *filename,
                const char *desc);
 void file_unlock(int fd, const char *desc);
+void file_show(const char *filename);
 
 /** @} */
 

+ 1 - 0
lib/dpkg/libdpkg.map

@@ -92,6 +92,7 @@ LIBDPKG_PRIVATE {
 	dir_sync_contents;
 
 	file_copy_perms;
+	file_show;
 
 	atomic_file_new;
 	atomic_file_open;