CS318 - Pintos
Pintos source browser for JHU CS318 course
mcat.c
Go to the documentation of this file.
1 /** mcat.c
2 
3  Prints files specified on command line to the console, using
4  mmap. */
5 
6 #include <stdio.h>
7 #include <syscall.h>
8 
9 int
10 main (int argc, char *argv[])
11 {
12  int i;
13 
14  for (i = 1; i < argc; i++)
15  {
16  int fd;
17  mapid_t map;
18  void *data = (void *) 0x10000000;
19  int size;
20 
21  /* Open input file. */
22  fd = open (argv[i]);
23  if (fd < 0)
24  {
25  printf ("%s: open failed\n", argv[i]);
26  return EXIT_FAILURE;
27  }
28  size = filesize (fd);
29 
30  /* Map files. */
31  map = mmap (fd, data);
32  if (map == MAP_FAILED)
33  {
34  printf ("%s: mmap failed\n", argv[i]);
35  return EXIT_FAILURE;
36  }
37 
38  /* Write file to console. */
39  write (STDOUT_FILENO, data, size);
40 
41  /* Unmap files (optional). */
42  munmap (map);
43  }
44  return EXIT_SUCCESS;
45 }
STDOUT_FILENO
#define STDOUT_FILENO
Definition: stdio.h:16
write
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
main
int main(int argc, char *argv[])
mcat.c
Definition: mcat.c:10
EXIT_FAILURE
#define EXIT_FAILURE
Unsuccessful execution.
Definition: syscall.h:20
MAP_FAILED
#define MAP_FAILED
Definition: syscall.h:13
printf
int printf(const char *format,...)
Writes formatted output to the console.
Definition: stdio.c:79
open
int open(const char *file)
Definition: syscall.c:103
EXIT_SUCCESS
#define EXIT_SUCCESS
Typical return values from main() and arguments to exit().
Definition: syscall.h:19
filesize
int filesize(int fd)
Definition: syscall.c:109
mmap
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
munmap
void munmap(mapid_t mapid)
Definition: syscall.c:151
mapid_t
int mapid_t
Map region identifier.
Definition: syscall.h:12