~ubuntu-branches/ubuntu/karmic/modglue/karmic

« back to all changes in this revision

Viewing changes to examples/periodic.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kasper Peeters
  • Date: 2009-01-17 15:20:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090117152000-w7adpc10bg9bjzow
Tags: upstream-1.12
ImportĀ upstreamĀ versionĀ 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 
 
3
        Test program to yield output at given interval.
 
4
        Copyright (C) 2001-2009  Kasper Peeters <kasper.peeters@aei.mpg.de>
 
5
 
 
6
   This program is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU General Public License
 
8
   as published by the Free Software Foundation; either version 2
 
9
   of the License, or (at your option) any later version.
 
10
   
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
   
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
        
 
20
*/
 
21
 
 
22
#include <string.h>
 
23
#include <unistd.h>
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
 
 
27
int main(int argc, char **argv)
 
28
        {
 
29
        int counter=1;
 
30
        char buffer[100];
 
31
 
 
32
        while(true) {
 
33
                if(argc>1) {
 
34
                        if(write(1, argv[1], strlen(argv[1]))<strlen(argv[1]))
 
35
                                exit(1);
 
36
                        }
 
37
                else { 
 
38
                        sprintf(buffer, "test %d", counter);
 
39
                        if(write(1, buffer, strlen(buffer))<strlen(buffer))
 
40
                                exit(1);
 
41
                        }
 
42
                ++counter;
 
43
                write(1, "\n", 1);
 
44
                sleep(1);
 
45
                }
 
46
        return 0;
 
47
        }