This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 012/114] Add mntent family functions for Phoenix.


From: Kuba Sejdak <jakub.sejdak@phoesys.com>

---
 newlib/libc/sys/phoenix/endmntent.c | 25 ++++++++++
 newlib/libc/sys/phoenix/getmntent.c | 95 +++++++++++++++++++++++++++++++++++++
 newlib/libc/sys/phoenix/setmntent.c | 24 ++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 newlib/libc/sys/phoenix/endmntent.c
 create mode 100644 newlib/libc/sys/phoenix/getmntent.c
 create mode 100644 newlib/libc/sys/phoenix/setmntent.c

diff --git a/newlib/libc/sys/phoenix/endmntent.c b/newlib/libc/sys/phoenix/endmntent.c
new file mode 100644
index 0000000..deb90f8
--- /dev/null
+++ b/newlib/libc/sys/phoenix/endmntent.c
@@ -0,0 +1,25 @@
+/* Copyright (C) 2012-2016 Phoenix Systems (http://www.phoesys.com/).
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdio.h>
+
+int endmntent(FILE *fp)
+{
+	fclose(fp);
+	return 1;
+}
diff --git a/newlib/libc/sys/phoenix/getmntent.c b/newlib/libc/sys/phoenix/getmntent.c
new file mode 100644
index 0000000..4e4e174
--- /dev/null
+++ b/newlib/libc/sys/phoenix/getmntent.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 2012-2016 Phoenix Systems (http://www.phoesys.com/).
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <mntent.h>
+#include <malloc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define COLUMN_FS_NAME			0
+#define COLUMN_MOUNTPOINT		1
+#define COLUMN_FS_TYPE			2
+#define COLUMN_OPTS				3
+#define COLUMN_DUMP_FREQ		4
+#define COLUMN_PASSNO			5
+
+#define BUFFER_SIZE				4096
+
+struct mntent *getmntent_r(FILE *fp, struct mntent *result, char *buffer, int bufsize)
+{
+	char *token, *buff_ptr;
+	char *line = NULL;
+	size_t size = 0;
+	int i;
+
+	buff_ptr = buffer;
+
+	if (getline(&line, &size, fp) == -1) {
+		free(line);
+		return NULL;
+	}
+
+	for (token = strtok(line, " "), i = 0; token != NULL; token = strtok(NULL, " "), ++i) {
+		if (((buff_ptr + strlen(token) + 1) - buffer) > bufsize) {
+			errno = ENOBUFS;
+			free(line);
+			return NULL;
+		}
+
+		switch (i) {
+		case COLUMN_FS_NAME:
+			result->mnt_fsname = strcpy(buff_ptr, token);
+			break;
+		case COLUMN_MOUNTPOINT:
+			result->mnt_dir = strcpy(buff_ptr, token);
+			break;
+		case COLUMN_FS_TYPE:
+			result->mnt_type = strcpy(buff_ptr, token);
+			break;
+		case COLUMN_OPTS:
+			result->mnt_opts = strcpy(buff_ptr, token);
+			break;
+		case COLUMN_DUMP_FREQ:
+			result->mnt_freq = atoi(token);
+			break;
+		case COLUMN_PASSNO:
+			result->mnt_passno = atoi(token);
+			break;
+		default:
+			free(line);
+			return NULL;
+		}
+
+		buff_ptr += strlen(token) + 1;
+	}
+
+	free(line);
+	return result;
+}
+
+struct mntent *getmntent(FILE *fp)
+{
+	static struct mntent result;
+	static char buffer[BUFFER_SIZE];
+	memset(&result, 0, sizeof(struct mntent));
+	memset(buffer, 0, sizeof(buffer));
+
+	return getmntent_r(fp, &result, buffer, sizeof(buffer));
+}
diff --git a/newlib/libc/sys/phoenix/setmntent.c b/newlib/libc/sys/phoenix/setmntent.c
new file mode 100644
index 0000000..b862894
--- /dev/null
+++ b/newlib/libc/sys/phoenix/setmntent.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2012-2016 Phoenix Systems (http://www.phoesys.com/).
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdio.h>
+
+FILE *setmntent(const char *filename, const char *type)
+{
+	return fopen(filename, type);
+}
-- 
2.5.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]