Просмотр исходного кода

libdpkg: Add support for interpreting filename '-' as stdin

Add a new flag so that the caller can request this new interpretation
explicitly w/o needing to change the semantics of the filename for the
normal case.
Guillem Jover лет назад: 12
Родитель
Сommit
a26fce6a81
2 измененных файлов с 6 добавлено и 0 удалено
  1. 2 0
      lib/dpkg/dpkg-db.h
  2. 4 0
      lib/dpkg/parse.c

+ 2 - 0
lib/dpkg/dpkg-db.h

@@ -298,6 +298,8 @@ enum parsedbflags {
   pdb_lax_parser		= pdb_lax_version_parser,
   /** Close file descriptor on context destruction. */
   pdb_close_fd			= DPKG_BIT(7),
+  /** Interpret filename ‘-’ as stdin. */
+  pdb_dash_is_stdin		= DPKG_BIT(8),
 
   /* Standard operations. */
 

+ 4 - 0
lib/dpkg/parse.c

@@ -531,6 +531,10 @@ parsedb_open(const char *filename, enum parsedbflags flags)
   struct parsedb_state *ps;
   int fd;
 
+  /* Special case stdin handling. */
+  if (flags & pdb_dash_is_stdin && strcmp(filename, "-") == 0)
+    return parsedb_new(filename, STDIN_FILENO, flags);
+
   fd = open(filename, O_RDONLY);
   if (fd == -1)
     ohshite(_("failed to open package info file `%.255s' for reading"),