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