~ubuntu-branches/ubuntu/trusty/mstflint/trusty-updates

« back to all changes in this revision

Viewing changes to mwrite.c

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-03-30 00:19:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100330001900-a4oyvb4ioi6w6gvh
Tags: upstream-1.4-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.4-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  mwrite.c - CR Space write access
 
4
 *
 
5
 */
 
6
#include "mtcr.h"
 
7
 
 
8
#include <stdio.h>
 
9
#include <stdlib.h>
 
10
#include <string.h>
 
11
 
 
12
 
 
13
void usage(const char *n)
 
14
{
 
15
    printf("%s <device> <addr> <value>\n", n);
 
16
    exit(1);
 
17
}
 
18
 
 
19
int main(int ac, char *av[])
 
20
{
 
21
    char          *endp;
 
22
    int           rc=0;
 
23
    unsigned int  addr, val;
 
24
    mfile         *mf;
 
25
 
 
26
    if (ac != 4)
 
27
        usage(av[0]);
 
28
 
 
29
    addr = strtoul(av[2], &endp, 0);
 
30
    if (*endp)
 
31
        usage(av[0]);
 
32
    val = strtoul(av[3], &endp, 0);
 
33
    if (*endp)
 
34
        usage(av[0]);
 
35
 
 
36
    mf = mopen(av[1]);
 
37
    if ( !mf )
 
38
    {
 
39
        perror("mopen");
 
40
        return 1;
 
41
    }
 
42
 
 
43
    if ((rc = mwrite4(mf, addr, val)) < 0)
 
44
    {
 
45
        mclose(mf);
 
46
        perror("mwrite");
 
47
        return 1;
 
48
    }
 
49
    if (rc < 4)
 
50
    {
 
51
        mclose(mf);
 
52
        printf("Write only %d bytes\n", rc);
 
53
        return 1;
 
54
    }
 
55
    mclose(mf);
 
56
    return 0;
 
57
}