~vibhavp/ubuntu/raring/dahdi-tools/merge-from-debian

« back to all changes in this revision

Viewing changes to pattest.c

  • Committer: Vibhav Pant
  • Date: 2012-12-26 17:23:16 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: vibhavp@gmail.com-20121226172316-o2jojsfcnr0aqrme
* Merge from Debian unstable. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - debian/control: Added gawk as dependency for dkms build (LP: #493304)
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source 

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <linux/types.h>
34
34
#include <linux/ppp_defs.h> 
35
35
#include <sys/ioctl.h>
 
36
#include <sys/stat.h>
36
37
#include <unistd.h>
37
38
#include <stdlib.h>
38
39
#include "bittest.h"
43
44
#define BLOCK_SIZE 2039
44
45
#define DEVICE    "/dev/dahdi/channel"
45
46
 
46
 
static const char       rcsid[] = "$Id: pattest.c 7658 2009-12-02 19:45:45Z tzafrir $";
 
47
static const char       rcsid[] = "$Id: pattest.c 9975 2011-06-07 19:44:34Z kmoore $";
47
48
char                    *prog_name;
48
49
 
49
50
static void usage(void)
64
65
        printf("}\n");
65
66
}
66
67
 
67
 
int channel_open(char *name, int *bs)
 
68
int channel_open(const char *name, int *bs)
68
69
{
69
 
        int                     channo;
70
 
        int                     fd;
71
 
        struct                  dahdi_params tp;
72
 
        char                    *dev;
73
 
 
74
 
        channo = atoi(name);
75
 
        /* channo==0: The user passed a file name to be opened. */
76
 
        dev = channo ? DEVICE : name;
77
 
 
78
 
        fd = open(dev, O_RDWR, 0600);
79
 
 
80
 
        if (fd < 0) {
81
 
                perror(DEVICE);
82
 
                return -1;
83
 
        }
84
 
 
85
 
        /* If we got a channel number, get it from /dev/dahdi/channel: */
86
 
        if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
87
 
                perror("SPECIFY");
88
 
                return -1;
89
 
        }
90
 
        if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
 
70
        int     channo, fd;
 
71
        struct  dahdi_params tp;
 
72
        struct  stat filestat;
 
73
 
 
74
        /* stat file, if character device, open it */
 
75
        channo = strtoul(name, NULL, 10);
 
76
        fd = stat(name, &filestat);
 
77
        if (!fd && S_ISCHR(filestat.st_mode)) {
 
78
                fd = open(name, O_RDWR, 0600);
 
79
                if (fd < 0) {
 
80
                        perror(name);
 
81
                        return -1;
 
82
                }
 
83
        /* try out the dahdi_specify interface */
 
84
        } else if (channo > 0) {
 
85
                fd = open(DEVICE, O_RDWR, 0600);
 
86
                if (fd < 0) {
 
87
                        perror(DEVICE);
 
88
                        return -1;
 
89
                }
 
90
                if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
 
91
                        perror("DAHDI_SPECIFY ioctl failed");
 
92
                        return -1;
 
93
                }
 
94
        /* die */
 
95
        } else {
 
96
                fprintf(stderr, "Specified channel is not a valid character "
 
97
                        "device or channel number");
 
98
                return -1;
 
99
        }
 
100
 
 
101
        if (ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
91
102
                perror("SET_BLOCKSIZE");
92
103
                return -1;
93
104
        }