~ubuntu-branches/ubuntu/wily/dctrl-tools/wily

« back to all changes in this revision

Viewing changes to lib/fsaf.h

  • Committer: Package Import Robot
  • Author(s): Antti-Juhani Kaijanaho, David Prévot, Antti-Juhani Kaijanaho
  • Date: 2013-05-07 23:16:00 UTC
  • mfrom: (17.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130507231600-qb8annjvc7l32oak
Tags: 2.23
[ David Prévot ]

* Fix charset in pt_BR program translation.

[ Antti-Juhani Kaijanaho ]

* Merge 2.22.1 and 2.22.2.
* Add a test case (tests/0021.{in,out,sh}) to verify that tbl-dctrl
  handles UTF-8 correctly.
   - As it requires the C.UTF-8 locale, build-depend on libc-bin >= 2.13
* Since mblen is unnecessarily marked warn_unused_result with
  _FORTIFY_SOURCE, (see bug #674917), causing spurious warnings upon
  mblen initialization calls, switch to using mbrlen in tbl-dctrl.c (a
  good idea in any case).
* Add -Wextra to non-package builds (and clean up the resulting warnings).
* lib/msg.c (msg_primitive): Write the period before the newline, not after!
* tests/0022.{out,err,fails}: New test case, for grep-dctrl
  --ignore-parse-errors
* tester.sh: Handle missing diffs gracefully.
* lib/fsaf.c and others: Remove mmap support (recognize but ignore --mmap).
  It was only complicating matters without giving much benefit.
* lib/fsaf.[ch]: Make fsaf_read an inline function (50 % speedup in my
  tests.)
* debian/control (Build-Depends): Remove versioned gcc
  Thanks to Jakub Wilk for pointing out the version spec was broken.
  It also turns out to be obsolete.
* Some code cleanup.
* debian/control: Add "Multi-Arch: foreign"
  Closes: 693474 (Add multiarch metadata)
  Reported by Wookey <wookey@wookware.org>.
* po/fi.po: Fix charset issue discovered by Jakub Wilk
  and reported by David Prévot, and delete obsolete entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  dctrl-tools - Debian control file inspection tools
2
 
    Copyright © 2003, 2005 Antti-Juhani Kaijanaho
 
2
    Copyright © 2003, 2005, 2012 Antti-Juhani Kaijanaho
3
3
 
4
4
    This program is free software; you can redistribute it and/or modify
5
5
    it under the terms of the GNU General Public License as published by
35
35
        size_t buf_size;
36
36
        size_t invalid_mark;
37
37
        size_t eof_mark; /* can be (size_t)(-1) if not reached yet */
38
 
#ifdef _POSIX_MAPPED_FILES
39
 
        bool mapped;
40
 
        size_t topread; /* marks the top of what has been read ahead */
41
 
#endif
42
38
};
43
39
 
44
40
typedef struct fsaf_private FSAF;
45
41
 
46
 
/* True if FSAF should not use mmap even if it is possible. */
47
 
extern bool fsaf_mmap;
48
 
 
49
42
/* Open a FSAF for the given fd. Only read access is supported for
50
43
 * now.  The whole file is initially valid.  */
51
44
FSAF * fsaf_fdopen(int fd, char const *fname);
61
54
struct fsaf_read_rv {
62
55
        char const * b;
63
56
        size_t len;
64
 
} fsaf_read(FSAF *, size_t offset, size_t len);
 
57
};
 
58
static inline
 
59
struct fsaf_read_rv fsaf_read(FSAF * fp, size_t offset, size_t len)
 
60
{
 
61
        void fsaf_slurp(FSAF * fp, size_t len);
 
62
 
 
63
        /* Reading nothing - since offset can be bogus in this
 
64
         * situation, this could foul up our assumptions later, so
 
65
         * return already here. */
 
66
        if (len == 0) {
 
67
                return (struct fsaf_read_rv){ .b = "", .len = 0 };
 
68
        }
 
69
 
 
70
        /* Make sure we don't read past the EOF mark.  */
 
71
        if (offset + len > fp->eof_mark) len = fp->eof_mark - offset;
 
72
 
 
73
        /* Ensure that we have enough data in the buffer. */
 
74
        assert(offset >= fp->buf_offset);
 
75
        if (offset - fp->buf_offset + len > fp->buf_size) {
 
76
                fsaf_slurp(fp, offset - fp->buf_offset + len - fp->buf_size);
 
77
                if (offset - fp->buf_offset + len > fp->buf_size) {
 
78
                        len = fp->buf_size - (offset - fp->buf_offset);
 
79
                }
 
80
        }
 
81
        
 
82
        assert(offset - fp->buf_offset + len <= fp->buf_size);
 
83
        assert(offset + len <= fp->eof_mark);
 
84
        return (struct fsaf_read_rv){
 
85
                .b = fp->buf + (offset - fp->buf_offset),
 
86
                .len = len
 
87
        };
 
88
}
65
89
 
66
90
/* Behaves like fsaf_read except that the result is put in a malloc'd
67
91
 * zero-terminated buffer.  NULL return value indicates either memory