~ubuntu-branches/debian/sid/mstflint/sid

« back to all changes in this revision

Viewing changes to small_utils/mwrite.c

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2014-07-04 15:39:23 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140704153923-khknwv3o1jeap3oo
Tags: 3.7.0-1
* New upstream release: 3.7.0-1.10.gdf7ec73
* Add build depends on libibmad-dev and autotools-dev.
* Remove build depends on automake and libtool.
* Switch to dh 9 and source format version 3.0
* Remove placeholder manpages.
* Remove flag DM-Upload-Allowed.
* Remove all current Uploaders, they're welcome back anytime.
  Add myself to Uploaders.
* Bump Standards-Version to 3.9.5 (no changes required).
* Update homepage.
* Add a watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved.
 
3
 * 
 
4
 * This software is available to you under a choice of one of two
 
5
 * licenses.  You may choose to be licensed under the terms of the GNU
 
6
 * General Public License (GPL) Version 2, available from the file
 
7
 * COPYING in the main directory of this source tree, or the
 
8
 * OpenIB.org BSD license below:
 
9
 * 
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 * 
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 * 
 
18
 *      - Redistributions in binary form must reproduce the above
 
19
 *        copyright notice, this list of conditions and the following
 
20
 *        disclaimer in the documentation and/or other materials
 
21
 *        provided with the distribution.
 
22
 * 
 
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
24
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
26
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
27
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
28
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
29
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
30
 * SOFTWARE.
 
31
 */
 
32
/*
 
33
 *
 
34
 *  mwrite.c - CR Space write access
 
35
 *
 
36
 */
 
37
#include "mtcr.h"
 
38
 
 
39
#include <stdio.h>
 
40
#include <stdlib.h>
 
41
#include <string.h>
 
42
 
 
43
 
 
44
void usage(const char *n)
 
45
{
 
46
    printf("%s <device> <addr> <value>\n", n);
 
47
    exit(1);
 
48
}
 
49
 
 
50
int main(int ac, char *av[])
 
51
{
 
52
    char          *endp;
 
53
    int           rc=0;
 
54
    unsigned int  addr, val;
 
55
    mfile         *mf;
 
56
 
 
57
    if (ac != 4)
 
58
        usage(av[0]);
 
59
 
 
60
    addr = strtoul(av[2], &endp, 0);
 
61
    if (*endp)
 
62
        usage(av[0]);
 
63
    val = strtoul(av[3], &endp, 0);
 
64
    if (*endp)
 
65
        usage(av[0]);
 
66
 
 
67
    mf = mopen(av[1]);
 
68
    if ( !mf )
 
69
    {
 
70
        perror("mopen");
 
71
        return 1;
 
72
    }
 
73
 
 
74
    if ((rc = mwrite4(mf, addr, val)) < 0)
 
75
    {
 
76
        mclose(mf);
 
77
        perror("mwrite");
 
78
        return 1;
 
79
    }
 
80
    if (rc < 4)
 
81
    {
 
82
        mclose(mf);
 
83
        printf("Write only %d bytes\n", rc);
 
84
        return 1;
 
85
    }
 
86
    mclose(mf);
 
87
    return 0;
 
88
}