akaros/tests/write_to.c
<<
>>
Prefs
   1/* Debugging app.
   2 *
   3 * write_to PATH STRING
   4 *
   5 * opens PATH, writes STRING to it */
   6
   7#include <stdlib.h>
   8#include <stdio.h>
   9#include <string.h>
  10#include <unistd.h>
  11#include <assert.h>
  12#include <parlib/net.h>
  13
  14#include <sys/types.h>
  15#include <sys/stat.h>
  16#include <fcntl.h>
  17
  18int main(int argc, char *argv[])
  19{
  20        char *path, *string;
  21        int fd, ret;
  22
  23        if (argc != 3) {
  24                printf("Usage: %s PATH STRING\n", argv[0]);
  25                exit(-1);
  26        }
  27        path = argv[1];
  28        string = argv[2];
  29
  30        fd = open(path, O_RDWR);
  31        if (fd < 0) {
  32                perror("Can't open path");
  33                exit(-1);
  34        }
  35        ret = write(fd, string, strlen(string));
  36        if (ret < 0) {
  37                perror("Failed to write string");
  38                close(fd);
  39                exit(-1);
  40        }
  41        close(fd);
  42}
  43