0N/A/*
2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include <stdio.h>
0N/A#include <errno.h>
0N/A#include <unistd.h>
0N/A#include <fcntl.h>
0N/A#include <sys/stat.h>
0N/A
0N/A/**
0N/A * Generates sun.nio.fs.UnixConstants
0N/A */
0N/A
0N/Astatic void out(char* s) {
0N/A printf("%s\n", s);
0N/A}
0N/A
0N/Astatic void emit(char* name, int value) {
0N/A printf(" static final int %s = %d;\n", name, value);
0N/A}
0N/A
0N/Astatic void emitX(char* name, int value) {
0N/A printf(" static final int %s = 0x%x;\n", name, value);
0N/A}
0N/A
0N/A#define DEF(X) emit(#X, X);
0N/A#define DEFX(X) emitX(#X, X);
0N/A
0N/Aint main(int argc, const char* argv[]) {
0N/A out("// AUTOMATICALLY GENERATED FILE - DO NOT EDIT ");
out("package sun.nio.fs; ");
out("class UnixConstants { ");
out(" private UnixConstants() { } ");
// open flags
DEF(O_RDONLY);
DEF(O_WRONLY);
DEF(O_RDWR);
DEFX(O_APPEND);
DEFX(O_CREAT);
DEFX(O_EXCL);
DEFX(O_TRUNC);
DEFX(O_SYNC);
#ifndef O_DSYNC
// At least FreeBSD doesn't define O_DSYNC
emit("O_DSYNC", O_SYNC);
#else
DEFX(O_DSYNC);
#endif
#ifdef O_NOFOLLOW
DEFX(O_NOFOLLOW);
#else
// not supported (dummy values will not be used at runtime).
emitX("O_NOFOLLOW", 0x0);
#endif
// mode masks
emitX("S_IAMB",
(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH));
DEF(S_IRUSR);
DEF(S_IWUSR);
DEF(S_IXUSR);
DEF(S_IRGRP);
DEF(S_IWGRP);
DEF(S_IXGRP);
DEF(S_IROTH);
DEF(S_IWOTH);
DEF(S_IXOTH);
DEFX(S_IFMT);
DEFX(S_IFREG);
DEFX(S_IFDIR);
DEFX(S_IFLNK);
DEFX(S_IFCHR);
DEFX(S_IFBLK);
DEFX(S_IFIFO);
// access modes
DEF(R_OK);
DEF(W_OK);
DEF(X_OK);
DEF(F_OK);
// errors
DEF(ENOENT);
DEF(EACCES);
DEF(EEXIST);
DEF(ENOTDIR);
DEF(EINVAL);
DEF(EXDEV);
DEF(EISDIR);
DEF(ENOTEMPTY);
DEF(ENOSPC);
DEF(EAGAIN);
DEF(ENOSYS);
DEF(ELOOP);
DEF(EROFS);
#ifndef ENODATA
// Only used in Linux java source, provide any value so it compiles
emit("ENODATA", ELAST);
#else
DEF(ENODATA);
#endif
DEF(ERANGE);
// flags used with openat/unlinkat/etc.
#if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_REMOVEDIR)
DEFX(AT_SYMLINK_NOFOLLOW)
DEFX(AT_REMOVEDIR);
#else
// not supported (dummy values will not be used at runtime).
emitX("AT_SYMLINK_NOFOLLOW", 0x0);
emitX("AT_REMOVEDIR", 0x0);
#endif
out("} ");
return 0;
}