jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c
changeset 2057 3acf8e5e2ca0
child 3065 452aaa2899fc
equal deleted inserted replaced
2056:115e09b7a004 2057:3acf8e5e2ca0
       
     1 /*
       
     2  * Copyright 2008-2009 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 #include <stdio.h>
       
    27 #include <errno.h>
       
    28 #include <unistd.h>
       
    29 #include <sys/fcntl.h>
       
    30 #include <sys/stat.h>
       
    31 
       
    32 /**
       
    33  * Generates sun.nio.fs.UnixConstants
       
    34  */
       
    35 
       
    36 static void out(char* s) {
       
    37     printf("%s\n", s);
       
    38 }
       
    39 
       
    40 static void emit(char* name, int value) {
       
    41     printf("    static final int %s = %d;\n", name, value);
       
    42 }
       
    43 
       
    44 static void emitX(char* name, int value) {
       
    45     printf("    static final int %s = 0x%x;\n", name, value);
       
    46 }
       
    47 
       
    48 #define DEF(X) emit(#X, X);
       
    49 #define DEFX(X) emitX(#X, X);
       
    50 
       
    51 int main(int argc, const char* argv[]) {
       
    52     out("// AUTOMATICALLY GENERATED FILE - DO NOT EDIT                                  ");
       
    53     out("package sun.nio.fs;                                                            ");
       
    54     out("class UnixConstants {                                                          ");
       
    55     out("    private UnixConstants() { }                                                ");
       
    56 
       
    57     // open flags
       
    58     DEF(O_RDONLY);
       
    59     DEF(O_WRONLY);
       
    60     DEF(O_RDWR);
       
    61     DEFX(O_APPEND);
       
    62     DEFX(O_CREAT);
       
    63     DEFX(O_EXCL);
       
    64     DEFX(O_TRUNC);
       
    65     DEFX(O_SYNC);
       
    66     DEFX(O_DSYNC);
       
    67     DEFX(O_NOFOLLOW);
       
    68 
       
    69     // flags used with openat/unlinkat/etc.
       
    70 #ifdef __solaris__
       
    71     DEFX(AT_SYMLINK_NOFOLLOW);
       
    72     DEFX(AT_REMOVEDIR);
       
    73 #endif
       
    74 #ifdef __linux__
       
    75     emitX("AT_SYMLINK_NOFOLLOW", 0x100);        // since 2.6.16
       
    76     emitX("AT_REMOVEDIR", 0x200);
       
    77 #endif
       
    78 
       
    79     // mode masks
       
    80     emitX("S_IAMB",
       
    81          (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH));
       
    82     DEF(S_IRUSR);
       
    83     DEF(S_IWUSR);
       
    84     DEF(S_IXUSR);
       
    85     DEF(S_IRGRP);
       
    86     DEF(S_IWGRP);
       
    87     DEF(S_IXGRP);
       
    88     DEF(S_IROTH);
       
    89     DEF(S_IWOTH);
       
    90     DEF(S_IXOTH);
       
    91     DEFX(S_IFMT);
       
    92     DEFX(S_IFREG);
       
    93     DEFX(S_IFDIR);
       
    94     DEFX(S_IFLNK);
       
    95     DEFX(S_IFCHR);
       
    96     DEFX(S_IFBLK);
       
    97     DEFX(S_IFIFO);
       
    98 
       
    99     // access modes
       
   100     DEF(R_OK);
       
   101     DEF(W_OK);
       
   102     DEF(X_OK);
       
   103     DEF(F_OK);
       
   104 
       
   105     // errors
       
   106     DEF(ENOENT);
       
   107     DEF(EACCES);
       
   108     DEF(EEXIST);
       
   109     DEF(ENOTDIR);
       
   110     DEF(EINVAL);
       
   111     DEF(EXDEV);
       
   112     DEF(EISDIR);
       
   113     DEF(ENOTEMPTY);
       
   114     DEF(ENOSPC);
       
   115     DEF(EAGAIN);
       
   116     DEF(ENOSYS);
       
   117     DEF(ELOOP);
       
   118     DEF(EROFS);
       
   119     DEF(ENODATA);
       
   120     DEF(ERANGE);
       
   121 
       
   122     out("}                                                                              ");
       
   123 
       
   124     return 0;
       
   125 }