1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2009-, Sun Microsystems, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package com.sun.akuma;
25
26 import com.sun.jna.Library;
27 import com.sun.jna.Memory;
28 import com.sun.jna.NativeLong;
29 import com.sun.jna.StringArray;
30 import com.sun.jna.Native;
31 import com.sun.jna.Pointer;
32 import com.sun.jna.PointerType;
33 import com.sun.jna.ptr.IntByReference;
34
35 /**
36 * GNU C library.
37 */
38 public interface CLibrary extends Library {
39 int fork();
40 int kill(int pid, int signum);
41 int setsid();
42 int setuid(short newuid);
43 int setgid(short newgid);
44 int umask(int mask);
45 int getpid();
46 int getppid();
47 int chdir(String dir);
48 int execv(String file, StringArray args);
49 int setenv(String name, String value);
50 int unsetenv(String name);
51 void perror(String msg);
52 String strerror(int errno);
53
54 // this is listed in http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man3/sysctlbyname.3.html
55 // but not in http://www.gnu.org/software/libc/manual/html_node/System-Parameters.html#index-sysctl-3493
56 // perhaps it is only supported on BSD?
57 int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp, Pointer newp, IntByReference newlen);
58
59 int sysctl(int[] mib, int nameLen, Pointer oldp, IntByReference oldlenp, Pointer newp, IntByReference newlen);
60
61 int sysctlnametomib(String name, Pointer mibp, IntByReference size);
62
63 public class FILE extends PointerType {
64 public FILE() {
65 }
66
67 public FILE(Pointer pointer) {
68 super(pointer);
69 }
70 }
71
72 // Additional C functions we need on Solaris 64bit to seek to a place above Long.MAX_VALUE
73 FILE fopen(String fileName, String mode);
74 int fseek(FILE file, long offset, int whence);
75 long ftell(FILE file);
76 int fread(Pointer buf, int size, int count, FILE file);
77 int fclose(FILE file);
78
79 /**
80 * Read a symlink. The name will be copied into the specified memory, and returns the number of
81 * bytes copied. The string is not null-terminated.
82 *
83 * @return
84 * if the return value equals size, the caller needs to retry with a bigger buffer.
85 * If -1, error.
86 */
87 int readlink(String filename, Memory buffer, NativeLong size);
88
89 public static final CLibrary LIBC = (CLibrary) Native.loadLibrary("c",CLibrary.class);
90 }