~ubuntu-branches/debian/sid/geany-plugins/sid

« back to all changes in this revision

Viewing changes to geanygdb/src/ttyhelper.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2008 Jeff Pohlmeyer <yetanothergeek(at)gmail(dot)com>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * A little "shell" application to grab the tty name of a console..
 
19
 * The tty name is written to the file specified in argv[1] of the
 
20
 * command line. After that the program just runs in a loop that
 
21
 * calls nanosleep() until some external force causes it to exit.
 
22
 */
 
23
 
 
24
#include <stdio.h>
 
25
#include <time.h>
 
26
#include <unistd.h>
 
27
 
 
28
int
 
29
main(int argc, char *argv[])
 
30
{
 
31
        FILE *f;
 
32
        char *tty = NULL;
 
33
 
 
34
        if (argc != 2)
 
35
        {
 
36
                return 1;
 
37
        }
 
38
 
 
39
        if (!isatty(0))
 
40
        {
 
41
                return 1;
 
42
        }
 
43
 
 
44
        tty = ttyname(0);
 
45
 
 
46
        if (!(tty && *tty))
 
47
        {
 
48
                return 1;
 
49
        }
 
50
 
 
51
        f = fopen(argv[1], "w");
 
52
 
 
53
        if (!f)
 
54
        {
 
55
                return 1;
 
56
        }
 
57
 
 
58
        fprintf(f, "%s", tty);
 
59
 
 
60
        if (fclose(f) != 0)
 
61
        {
 
62
                return 1;
 
63
        }
 
64
 
 
65
        while (1)
 
66
        {
 
67
                struct timespec req = { 1, 0 }, rem;
 
68
                nanosleep(&req, &rem);
 
69
        }
 
70
 
 
71
        return 0;
 
72
}