-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtouchmod.java
77 lines (66 loc) · 2 KB
/
touchmod.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Reads standard input and writes to standard output
* and the named file.
* A simple tee program for a simulated file system.
* <p>
* Usage:
* <pre>
* java tee <i>output-file</i>
* </pre>
* @author Ray Ontko
*/
public class touchmod
{
/**
* The name of this program.
* This is the program name that is used
* when displaying error messages.
*/
public static final String PROGRAM_NAME = "touchmod" ;
/**
* Copies standard input to standard output and to a file.
* @exception java.lang.Exception if an exception is thrown
* by an underlying operation
*/
public static void main( String[] argv ) throws Exception
{
// initialize the file system simulator kernel
Kernel.initialize() ;
String modeBuffer = System.getProperty( "mode" ) ;
short mode = 0666;
if ( modeBuffer == null )
modeBuffer = "0666" ;
try
{
mode = Short.parseShort(modeBuffer, 8) ;
}
catch ( NumberFormatException e )
{
System.err.println( PROGRAM_NAME +
": invalid number for property mode" ) ;
System.exit( 1 ) ;
}
// print a helpful message if the number of arguments is not correct
if( argv.length != 1 )
{
System.err.println( PROGRAM_NAME + ": usage: java " + PROGRAM_NAME +
" output-file" ) ;
Kernel.exit( 1 ) ;
}
// give the command line argument a better name
String name = argv[0] ;
// create the output file
int out_fd = Kernel.creat( name , mode ) ;
if( out_fd < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME + ": unable to open output file \"" +
name + "\"" ) ;
Kernel.exit( 2 ) ;
}
// close the output file
Kernel.close( out_fd ) ;
// exit with success
Kernel.exit( 0 ) ;
}
}