Commit 02566928 authored by Guillem Jover's avatar Guillem Jover

libdpkg: Add new file_show() function

parent 12ffef5d
......@@ -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"));
}
......@@ -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);
/** @} */
......
......@@ -92,6 +92,7 @@ LIBDPKG_PRIVATE {
dir_sync_contents;
file_copy_perms;
file_show;
atomic_file_new;
atomic_file_open;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment