home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / lib / native / java.lang / java.lang.System.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  3.6 KB  |  148 lines

  1. /*
  2.  * java.lang.System.c
  3.  *
  4.  * Copyright (c) 1996 Systems Architecture Research Centre,
  5.  *           City University, London, UK.
  6.  *
  7.  * See the file "license.terms" for information on usage and redistribution
  8.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9.  *
  10.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <assert.h>
  15. #include <stdlib.h>
  16. #include <sys/utsname.h>
  17. #include <sys/time.h>
  18. #include <pwd.h>
  19. #include <unistd.h>
  20. #include <native.h>
  21. #include "system.h"
  22. #include "../java.util/java.util.Properties.h"
  23. #include "java.lang.System.h"
  24. #include "../../kaffe/itypes.h"
  25. #include "../../kaffe/classMethod.h"
  26.  
  27. /*
  28.  * Copy one part of an array to another.
  29.  */
  30. void
  31. java_lang_System_arraycopy(struct Hjava_lang_Object* src, long srcpos, struct Hjava_lang_Object* dst, long dstpos, long len)
  32. {
  33.     char* in;
  34.     char* out;
  35.     int elemsz;
  36.  
  37.     /* Must be some array type */
  38.     assert(dst->type->sig[0] == '[');
  39.     elemsz = TYPE_SIZE_C(dst->type->sig[1]);
  40.  
  41.     len *= elemsz;
  42.     srcpos *= elemsz;
  43.     dstpos *= elemsz;
  44.  
  45.     in = &src->data[srcpos];
  46.     out = &dst->data[dstpos];
  47.     for (; len > 0; len--) {
  48.         *out++ = *in++;
  49.     }
  50. }
  51.  
  52. /*
  53.  * Initialise system properties to their defaults.
  54.  */
  55. struct Hjava_util_Properties*
  56. java_lang_System_initProperties(struct Hjava_util_Properties* p)
  57. {
  58.     int r;
  59.     struct utsname system;
  60.     struct passwd* pw;
  61.     char* jhome;
  62.     char* cpath;
  63.     char* dir;
  64.  
  65.     /* Define PUT to be a call to the put method taking two strings
  66.      * as arguments.  call_java_method does all the majic looking up
  67.      * here.
  68.      */
  69. #define    PUT(k,s) \
  70.     do_execute_java_method(0, &p->obj, "put", \
  71.       "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", \
  72.       0, false, \
  73.       makeJavaString(k, strlen(k)), \
  74.       makeJavaString(s, strlen(s)))
  75.  
  76.     /* Now use it to add the default properties:
  77.      * java.version        Java version number
  78.      * java.vendor          Java vendor specific string
  79.      * java.vendor.url      Java vendor URL
  80.      * java.home            Java installation directory
  81.      * java.class.version   Java class version number
  82.      * java.class.path      Java classpath
  83.      * os.name              Operating System Name
  84.      * os.arch              Operating System Architecture
  85.      * os.version           Operating System Version
  86.      * file.separator       File separator ("/" on Unix)
  87.      * path.separator       Path separator (":" on Unix)
  88.      * line.separator       Line separator ("\n" on Unix)
  89.      * user.name            User account name
  90.      * user.home            User home directory
  91.      * user.dir             User's current working directory
  92.      */
  93.  
  94.     PUT("java.version", kaffe_version);
  95.     PUT("java.vendor", kaffe_vendor);
  96.     PUT("java.vendor.url", kaffe_vendor_url);
  97.  
  98.     jhome = getenv(KAFFEHOME);
  99.     if (jhome == 0) {
  100.         jhome = ".";
  101.     }
  102.     PUT("java.home", jhome);
  103.  
  104.     PUT("java.class.version", kaffe_class_version);
  105.  
  106.     cpath = getenv(KAFFECLASSPATH);
  107.     if (cpath == 0) {
  108.         cpath = ".";
  109.     }
  110.     PUT("java.class.path", cpath);
  111.  
  112.     /* Setup system properties */
  113.     r = uname(&system);
  114.     assert(r == 0);
  115.     PUT("os.name", system.sysname);
  116.     PUT("os.arch", system.machine);
  117.     PUT("os.version", system.version);
  118.  
  119.     PUT("file.separator", file_seperator);
  120.     PUT("path.separator", path_seperator);
  121.     PUT("line.separator", line_seperator);
  122.  
  123.     /* Setup user properties */
  124.     pw = getpwuid(getuid());
  125.     assert(pw != 0);
  126.     dir = getcwd(0, 0);
  127.     if (dir == 0) {
  128.         dir = ".";
  129.     }
  130.     PUT("user.name", pw->pw_name);
  131.     PUT("user.home", pw->pw_dir);
  132.     PUT("user.dir", dir);
  133.     free(dir);
  134.  
  135.     return (p);
  136. }
  137.  
  138. /*
  139.  * Return current time.
  140.  */
  141. long long
  142. java_lang_System_currentTimeMillis(void)
  143. {
  144.     struct timeval tm;
  145.     gettimeofday(&tm, 0);
  146.     return ((long long)(tm.tv_sec * 1000) + (long long)(tm.tv_usec / 1000));
  147. }
  148.