OpenCores
URL https://opencores.org/ocsvn/zet86/zet86/trunk

Subversion Repositories zet86

[/] [zet86/] [trunk/] [src/] [tools/] [splitlh.c] - Blame information for rev 52

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 zeus
#include <stdio.h>
2
#include <sys/stat.h>
3
#include <fcntl.h>
4
 
5
int main(int argc, char *argv[])
6
{
7
  int fd, count, out0, out1;
8
  char word[2];
9
 
10
  if (argc != 4) fprintf(stderr, "Syntax: %s infile evenfile oddfile\n",
11
                         argv[0]);
12
 
13
  fd=open(argv[1], O_RDONLY);
14
  if(fd < 0)
15
    {
16
      fprintf(stderr, "Error opening file\n");
17
      return 1;
18
    }
19
 
20
  out0 = open (argv[2], O_WRONLY|O_CREAT|O_TRUNC,
21
               S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
22
  if(out0 < 0)
23
    {
24
      fprintf(stderr, "Error creating even file\n");
25
      return 2;
26
    }
27
 
28
  out1 = open (argv[3], O_WRONLY|O_CREAT|O_TRUNC,
29
               S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
30
  if(out1 < 0)
31
    {
32
      fprintf(stderr, "Error creating odd file\n");
33
      return 3;
34
    }
35
 
36
  do {
37
    count = read(fd, word, 2);
38
    if (count > 0) write(out0, &word[0], 1);
39
    if (count > 1) write(out1, &word[1], 1);
40
  } while (count > 0);
41
 
42
  close (fd);
43
  close (out0);
44
  close (out1);
45
 
46
  return 0;
47
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.