diff -ur /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_getparam.c /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_getparam.c
--- /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_getparam.c	2014-05-07 15:22:07.020747045 +0530
+++ /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_getparam.c	2014-05-27 12:10:46.086540547 +0530
@@ -240,6 +240,7 @@
          /* 'buffer' listed as --no-buffer in the help */
   {"o",  "output",                   TRUE},
   {"O",  "remote-name",              FALSE},
+  {"O!", "remote-name-safe",         FALSE},
   {"Oa", "remote-name-all",          FALSE},
   {"p",  "proxytunnel",              FALSE},
   {"P",  "ftpport",                  TRUE},
@@ -269,6 +270,8 @@
   {"#",  "progress-bar",             FALSE},
   {":",  "next",                     FALSE},
   {"~",  "xattr",                    FALSE},
+      /* donot overwrte the exisiting file */
+  {"!",  "no_clobber",               FALSE}
 };
 
 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
@@ -389,6 +392,7 @@
   ParameterError err;
   bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
                          by using --OPTION or --no-OPTION */
+  static struct getout *_url;
 
 
   if(('-' != flag[0]) ||
@@ -992,6 +996,11 @@
     case '~': /* --xattr */
       config->xattr = toggle;
       break;
+    case '!': /* --no_clobber */
+      if(_url) {
+        _url->flags = _url->flags | GETOUT_OUTFILE_NOOVERWRITE;
+      }
+        break;
     case '0': /* --http* options */
       switch(subletter) {
       case '\0':
@@ -1521,6 +1530,9 @@
         /* there was no free node, create one! */
         url = new_getout(config);
 
+       /* used to take the pointer to be used in case 'n' above */
+        _url = url;
+
       if(!url)
         return PARAM_NO_MEM;
       else {
@@ -1536,6 +1548,10 @@
           else
             url->flags &= ~GETOUT_USEREMOTE; /* switch off */
         }
+        if('!' == subletter) {
+          url->flags = url->flags | GETOUT_OUTFILE_NOOVERWRITE;
+        }
+
         url->flags |= GETOUT_OUTFILE;
       }
     }
diff -ur /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_help.c /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_help.c
--- /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_help.c	2014-05-07 15:21:54.890762567 +0530
+++ /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_help.c	2014-05-26 20:21:06.702580214 +0530
@@ -178,6 +178,7 @@
   " -J, --remote-header-name Use the header-provided filename (H)",
   " -O, --remote-name   Write output to a file named as the remote file",
   "     --remote-name-all Use the remote file name for all URLs",
+  "     --remote-name-safe Do not overwrite existing file",
   " -R, --remote-time   Set the remote file's time on the local output",
   " -X, --request COMMAND  Specify request command to use",
   "     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS",
@@ -238,6 +239,8 @@
   " -w, --write-out FORMAT  What to output after completion",
   "     --xattr        Store metadata in extended file attributes",
   " -q                 If used as the first parameter disables .curlrc",
+  " -!  --no_clobber   Don't overwrite the exisiting ,rather create",
+  "                    seperate file ,used with -o and -O options",
   NULL
 };
 
diff -ur /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_operate.c /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_operate.c
--- /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_operate.c	2014-05-07 15:22:20.161763019 +0530
+++ /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_operate.c	2014-05-26 20:21:06.703580865 +0530
@@ -44,6 +44,7 @@
 #endif
 
 #include "rawstr.h"
+#define EXTRACHARS 10
 
 #define ENABLE_CURLX_PRINTF
 /* use our own printf() functions */
@@ -81,7 +82,6 @@
 #include "tool_vms.h"
 #include "tool_help.h"
 #include "tool_hugehelp.h"
-
 #include "memdebug.h" /* keep this as LAST include */
 
 #ifdef CURLDEBUG
@@ -187,6 +187,46 @@
 }
 #endif /* __VMS */
 
+/* function to check the existence of a file*/
+static bool fileexists(const char *outfile)
+{
+  bool fileisthere = FALSE;
+  int fp = open(outfile, O_RDONLY);
+
+  if(fp > 0) {
+    fileisthere = TRUE;
+    close(fp);
+  }
+  return fileisthere;
+}
+
+/* function to return the new file name on the basis of criterion set for file
+ * overwriting.
+ * */
+static char* returnnewfilename(const char* outputfilename)
+{
+  int i;
+  int newfilenamelength = strlen(outputfilename) + EXTRACHARS;
+  char *outputfilenamenew = malloc(newfilenamelength);
+
+  strncpy(outputfilenamenew,outputfilename,strlen(outputfilename));
+  for(i = 1; (fileexists(outputfilenamenew) && i < INT_MAX); i++) {
+    snprintf(outputfilenamenew,newfilenamelength,"%s.%d",outputfilename,i);
+    /* Purpose: This is used to convert the values into char array and creating
+     * the appropriate filename as per according to rules.
+     * */
+  }
+  if(outputfilename) {
+    free(outputfilename);
+  }
+  if(i >= INT_MAX && fileexists(outputfilenamenew)) {
+    return NULL; /* only filename.(INTMAX-1) filenames are */
+  }
+  outputfilename = strdup(outputfilenamenew);
+  free(outputfilenamenew);
+  return outputfilename;
+}
+
 static CURLcode operate_do(struct GlobalConfig *global,
                            struct OperationConfig *config)
 {
@@ -205,6 +245,7 @@
   int res = 0;
   unsigned long li;
 
+
   /* Save the values of noprogress and isatty to restore them later on */
   bool orig_noprogress = global->noprogress;
   bool orig_isatty = global->isatty;
@@ -538,9 +579,19 @@
            * decided we want to use the remote file name.
            */
 
-          if(!outfile) {
-            /* extract the file name from the URL */
-            res = get_url_file_name(&outfile, this_url);
+            if(!outfile) {
+              /* extract the file name from the URL */
+              res = get_url_file_name(&outfile, this_url);
+              if(urlnode->flags & GETOUT_OUTFILE_NOOVERWRITE) {
+                if(fileexists(outfile)) {
+                  outfile = returnnewfilename(outfile);
+                  if(outfile == NULL) {
+                    helpf(global->errors,"all possible filenames exhausted");
+                    goto quit_curl;
+                  }
+                }
+              }
+
             if(res)
               goto show_error;
             if((!outfile || !*outfile) && !config->content_disposition) {
@@ -561,6 +612,15 @@
           else if(urls) {
             /* fill '#1' ... '#9' terms from URL pattern */
             char *storefile = outfile;
+            if(urlnode->flags & GETOUT_OUTFILE_NOOVERWRITE) {
+              if(fileexists(outfile)) {
+                outfile = returnnewfilename(outfile);
+                if(outfile == NULL) {
+                  helpf(global->errors,"all possible filenames exhausted");
+                  goto quit_curl;
+                }
+              }
+            }
             res = glob_match_url(&outfile, storefile, urls);
             Curl_safefree(storefile);
             if(res) {
@@ -1845,6 +1905,5 @@
         helpf(config->errors, "out of memory\n");
     }
   }
-
   return result;
 }
diff -ur /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_sdecls.h /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_sdecls.h
--- /data2/2724/deepak.sn/verma.rk/oss/patch_generation/original/curl-7.36.0/src/tool_sdecls.h	2014-05-07 15:21:41.966733269 +0530
+++ /data2/2724/deepak.sn/verma.rk/oss/patch_generation/curl-7.36.0/src/tool_sdecls.h	2014-05-26 20:21:06.703580865 +0530
@@ -114,6 +114,8 @@
 #define GETOUT_UPLOAD     (1<<3)  /* if set, -T has been used */
 #define GETOUT_NOUPLOAD   (1<<4)  /* if set, -T "" has been used */
 #define GETOUT_METALINK   (1<<5)  /* set when Metalink download */
+#define GETOUT_OUTFILE_NOOVERWRITE (1<<6)
+/* set when we apply check for overwriting the exisiting file*/
 
 /*
  * 'trace' enumeration represents curl's output look'n feel possibilities.
