Permalink
Browse files

Renamed utils.h to util.h, added util.c.

  • Loading branch information...
1 parent 5333478 commit 86c2b7cc2dd9fb33161437dffca20b3ce33d3702 @iliya-gr committed Aug 17, 2012
Showing with 45 additions and 0 deletions.
  1. +43 −0 util.c
  2. +2 −0 utils.h → util.h
View
43 util.c
@@ -0,0 +1,43 @@
+// util.h
+// Copyright (C) 2012 Iliya Grushevskiy <iliya.gr@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <stdlib.h>
+#include <string.h>
+#include "util.h"
+
+char *sg_strerror(int error) {
+ char* errstr = NULL;
+
+ switch (error) {
+ case SGERROR_MEM_ALLOC:
+ errstr = "can't allocate memory";
+ break;
+ case SGERROR_FILE_WRITE:
+ errstr = "can't open file for writing";
+ break;
+ case SGERROR_NO_STREAM:
+ errstr = "no suitable streams found";
+ break;
+ case SGERROR_UNSUPPORTED_FORMAT:
+ errstr = "unsupported output format";
+ break;
+ default:
+ errstr = "unkown error";
+ break;
+ }
+
+ return strndup(errstr, strlen(errstr));
+}
View
@@ -26,4 +26,6 @@
#define SGERROR_UNSUPPORTED_FORMAT 0x03
#define SGERROR_FILE_WRITE 0x04
+char *sg_strerror(int error);
+
#endif

0 comments on commit 86c2b7c

Please sign in to comment.