comparison src/dmfile.c @ 958:985225a93aeb

Add error code parameter to dmError() and dmErrorVA().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 03:58:25 +0200
parents 1e5cf1144f36
children a0c187dae495
comparison
equal deleted inserted replaced
957:b66653c9acb3 958:985225a93aeb
74 else 74 else
75 if (filename != NULL) 75 if (filename != NULL)
76 { 76 {
77 if ((f = fopen(filename, "rb")) == NULL) 77 if ((f = fopen(filename, "rb")) == NULL)
78 { 78 {
79 dmError("Could not open '%s' for reading.\n", filename); 79 return dmError(DMERR_FOPEN,
80 return DMERR_FOPEN; 80 "Could not open '%s' for reading.\n", filename);
81 } 81 }
82 } 82 }
83 else 83 else
84 { 84 {
85 dmError("NULL filename and stream pointers.\n"); 85 return dmError(DMERR_NULLPTR,
86 return DMERR_NULLPTR; 86 "NULL filename and stream pointers.\n");
87 } 87 }
88 88
89 // Allocate initial data buffer 89 // Allocate initial data buffer
90 readSize = dataSize = BUF_SIZE_INITIAL; 90 readSize = dataSize = BUF_SIZE_INITIAL;
91 if ((dataBuf = dmMalloc(dataSize)) == NULL) 91 if ((dataBuf = dmMalloc(dataSize)) == NULL)
92 { 92 {
93 dmError("Error allocating memory for data, %d bytes.\n", dataSize); 93 res = dmError(DMERR_MALLOC,
94 res = DMERR_MALLOC; 94 "Error allocating memory for data, %d bytes.\n", dataSize);
95 goto error; 95 goto error;
96 } 96 }
97 97
98 dataPos = 0; 98 dataPos = 0;
99 dataRead = 0; 99 dataRead = 0;
108 { 108 {
109 readSize = BUF_SIZE_GROW; 109 readSize = BUF_SIZE_GROW;
110 dataSize += BUF_SIZE_GROW; 110 dataSize += BUF_SIZE_GROW;
111 if ((dataBuf = dmRealloc(dataBuf, dataSize)) == NULL) 111 if ((dataBuf = dmRealloc(dataBuf, dataSize)) == NULL)
112 { 112 {
113 dmError("Error reallocating memory for data, %d bytes.\n", dataSize); 113 res = dmError(DMERR_MALLOC,
114 res = DMERR_MALLOC; 114 "Error reallocating memory for data, %d bytes.\n",
115 dataSize);
115 goto error; 116 goto error;
116 } 117 }
117 } 118 }
118 else 119 else
119 break; 120 break;