|
6 | 6 | #include <kern/unistd.h>
|
7 | 7 | #include <current.h>
|
8 | 8 |
|
9 |
| -// Lab 2: Part B |
10 |
| -void sys___exit(int exitcode) { |
11 |
| - kprintf("exit: (%d)\n", exitcode); |
12 |
| - |
13 |
| - kprintf("Thread %s exited with code %d\n", curthread->t_name, exitcode); |
14 |
| - |
15 |
| - thread_exit(); |
16 |
| - |
17 |
| - panic("sys__exit: Thread did not exit properly\n"); |
18 |
| -} |
19 | 9 |
|
20 | 10 | // Lab 2: Part C
|
21 | 11 | int sys_printint(int c) {
|
22 |
| - kprintf("Given Number: %d\n", c); |
| 12 | + kprintf("Number: %d\n", c); |
23 | 13 |
|
24 | 14 | return (c % 2 == 0) ? 0 : 1;
|
25 | 15 | }
|
26 | 16 |
|
27 |
| -// Implement a simplified system call named int reversestring(const char *str, int len) |
28 |
| - |
29 |
| -// This system call should accept a string and length of the string as input and print the reverse of the string |
30 |
| -// using the internal kprintf( ) function. The return value should be 1 if the length of the string is multiple of |
31 |
| -// 5 or 0 otherwise. |
| 17 | +/* |
| 18 | +Implement a simplified system call named int reversestring(const char *str, int len) |
| 19 | +This system call should accept a string and length of the string as input and print the reverse of the string |
| 20 | +using the internal kprintf( ) function. The return value should be 1 if the length of the string is multiple of |
| 21 | +5 or 0 otherwise. |
| 22 | +*/ |
32 | 23 |
|
33 | 24 | // Lab 2: Part D
|
34 | 25 | int sys_reversestring(const char *str, int len) {
|
35 | 26 | kprintf("Given String: %s\n", str);
|
36 |
| - |
37 | 27 | for (int i = len - 1; i >= 0; i--) {
|
38 | 28 | kprintf("%c", str[i]);
|
39 | 29 | }
|
40 |
| - |
41 | 30 | kprintf("\n");
|
| 31 | + |
| 32 | + int isStringLenMultipleOf5 = 1; |
| 33 | + (len % 5 != 0) ? isStringLenMultipleOf5 = 0 : 1; |
| 34 | + kprintf("Return value: %d\n", isStringLenMultipleOf5); |
42 | 35 |
|
43 |
| - return (len % 5 == 0) ? 1 : 0; |
| 36 | + return isStringLenMultipleOf5; |
44 | 37 | }
|
45 | 38 |
|
0 commit comments