Index: uspace/app/bdsh/cmds/modules/touch/touch.c
===================================================================
--- uspace/app/bdsh/cmds/modules/touch/touch.c	(revision 36ab7c737a9b47469d540e94a850fab80bda101c)
+++ uspace/app/bdsh/cmds/modules/touch/touch.c	(revision 49ff5f3d72bdc099cbcb1c649dfa55c1104f1244)
@@ -27,6 +27,8 @@
  */
 
-/* TODO: Options that people would expect, such as not creating the file if
- * it doesn't exist, specifying the access time, etc */
+/*
+ * TODO: Options that people would expect, such as specifying the access time,
+ * etc.
+ */
 
 #include <stdio.h>
@@ -37,4 +39,7 @@
 #include <sys/types.h>
 #include <str.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <errno.h>
 
 #include "config.h"
@@ -47,15 +52,24 @@
 static const char *cmdname = "touch";
 
+static struct option const long_options[] = {
+	{ "no-create", no_argument, 0, 'c' },
+	{ 0, 0, 0, 0 }
+};
+
 /* Dispays help for touch in various levels */
 void help_cmd_touch(unsigned int level)
 {
 	if (level == HELP_SHORT) {
-		printf("`%s' updates access times for files\n", cmdname);
+		printf("`%s' updates access times of files\n", cmdname);
 	} else {
 		help_cmd_touch(HELP_SHORT);
-		printf("  `%s' <file>, if the file does not exist it will be "
-				"created\n", cmdname);
+		printf("Usage: `%s' [-c|--no-create] <file>...\n\n"
+		    "If the file does not exist it will be created empty,\n"
+		    "unless -c (--no-create) is supplied.\n\n"
+		    "Options:\n"
+		    "   -c, --no-create  Do not create new files\n",
+		    cmdname);
 	}
-
+	
 	return;
 }
@@ -64,39 +78,65 @@
 int cmd_touch(char **argv)
 {
-	unsigned int argc, i = 0, ret = 0;
-	int fd;
+	unsigned int argc = cli_count_args(argv);
+	unsigned int i = 0;
+	unsigned int ret = 0;
+	int c;
+	int longind;
+	bool no_create = false;
+	struct stat file_stat;
+	int fd = -1;
 	char *buff = NULL;
-
+	
 	DIR *dirp;
-
-	argc = cli_count_args(argv);
-
-	if (argc == 1) {
-		printf("%s - incorrect number of arguments. Try `help %s extended'\n",
-			cmdname, cmdname);
+	
+	for (c = 0, optind = 0, longind = 0; c != -1; ) {
+		c = getopt_long(argc, argv, "c", long_options, &longind);
+		switch (c) {
+		case 'c':
+			no_create = true;
+			break;
+		}
+	}
+	
+	if (argc - optind < 1) {
+		printf("%s: Incorrect number of arguments. Try `help %s extended'\n",
+		    cmdname, cmdname);
 		return CMD_FAILURE;
 	}
-
-	for (i = 1; i < argc; i ++) {
+	
+	for (i = optind; argv[i] != NULL; i++) {
 		buff = str_dup(argv[i]);
+		if (buff == NULL) {
+			cli_error(CL_ENOMEM, "Out of memory");
+			ret++;
+			continue;
+		}
+		
 		dirp = opendir(buff);
 		if (dirp) {
-			cli_error(CL_ENOTSUP, "%s is a directory", buff);
+			cli_error(CL_ENOTSUP, "`%s' is a directory", buff);
 			closedir(dirp);
-			ret ++;
+			free(buff);
+			ret++;
 			continue;
 		}
-
-		fd = open(buff, O_RDWR | O_CREAT);
+		
+		/* Check whether file exists if -c (--no-create) option is given */
+		if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == EOK)))
+			fd = open(buff, O_RDWR | O_CREAT);
+		
 		if (fd < 0) {
-			cli_error(CL_EFAIL, "Could not update / create %s ", buff);
-			ret ++;
+			cli_error(CL_EFAIL, "Could not update or create `%s'", buff);
+			free(buff);
+			ret++;
 			continue;
-		} else
+		} else {
 			close(fd);
-
+			fd = -1;
+		}
+		
 		free(buff);
 	}
-
+	
 	if (ret)
 		return CMD_FAILURE;
@@ -104,3 +144,2 @@
 		return CMD_SUCCESS;
 }
-
