1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* Licensed Materials - Property of IBM
*
* trousers - An open source TCG Software Stack
*
* (C) Copyright International Business Machines Corp. 2006
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "spi_utils.h"
#include "tspps.h"
#include "tsplog.h"
inline TSS_RESULT
read_data(int fd, void *data, UINT32 size)
{
int rc;
rc = read(fd, data, size);
if (rc == -1) {
LogError("read of %d bytes: %s", size, strerror(errno));
return TSPERR(TSS_E_INTERNAL_ERROR);
} else if ((unsigned)rc != size) {
LogError("read of %d bytes (only %d read)", size, rc);
return TSPERR(TSS_E_INTERNAL_ERROR);
}
return TSS_SUCCESS;
}
inline TSS_RESULT
write_data(int fd, void *data, UINT32 size)
{
int rc;
rc = write(fd, data, size);
if (rc == -1) {
LogError("write of %d bytes: %s", size, strerror(errno));
return TSPERR(TSS_E_INTERNAL_ERROR);
} else if ((unsigned)rc != size) {
LogError("write of %d bytes (only %d written)", size, rc);
return TSPERR(TSS_E_INTERNAL_ERROR);
}
return TSS_SUCCESS;
}
|