"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/test/test-posix-fadvise.c" (15 Mar 2019, 2264 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test-posix-fadvise.c": 0.09.49_vs_0.09.50.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 
   26 #include <unistd.h>
   27 #include <fcntl.h>
   28 
   29 #if defined(__gnu_hurd__)
   30 #error posix_fadvise is defined but not implemented and will always fail
   31 #endif
   32 
   33 #define NO_FADV
   34 
   35 int main(void)
   36 {
   37     static const char *filename = "/tmp/test-msync.tmp";
   38     int fd, ret, err = 1;
   39     void *ptr;
   40 
   41     fd = open(filename, O_RDWR | O_CREAT, 0666);
   42     if (fd < 0)
   43         return 1;
   44     (void)unlink(filename);
   45 
   46 #if defined(POSIX_FADV_NORMAL)
   47 #undef NO_FADV
   48     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_NORMAL);
   49     (void)ret;
   50 #endif
   51 #if defined(POSIX_FADV_SEQUENTIAL)
   52 #undef NO_FADV
   53     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_SEQUENTIAL);
   54     (void)ret;
   55 #endif
   56 #if defined(POSIX_FADV_RANDOM)
   57 #undef NO_FADV
   58     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_RANDOM);
   59     (void)ret;
   60 #endif
   61 #if defined(POSIX_FADV_NOREUSE)
   62 #undef NO_FADV
   63     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_NOREUSE);
   64     (void)ret;
   65 #endif
   66 #if defined(POSIX_FADV_WILLNEED)
   67 #undef NO_FADV
   68     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_WILLNEED);
   69     (void)ret;
   70 #endif
   71 #if defined(POSIX_FADV_DONTNEED)
   72 #undef NO_FADV
   73     ret = posix_fadvise(fd, 0, 1024, POSIX_FADV_DONTNEED);
   74     (void)ret;
   75 #endif
   76 
   77 #if defined(NO_FADV)
   78 #error no POSIX_FADV advice macros defined!
   79 #endif
   80 
   81 err:
   82     (void)close(fd);
   83 
   84     return err;
   85 }