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-16 18:35:03.132510636 +0530
@@ -240,6 +240,7 @@
          /* 'buffer' listed as --no-buffer in the help */
   {"o",  "output",                   TRUE},
   {"O",  "remote-name",              FALSE},
+  {"On", "remote-name-no-overwrite", FALSE},
   {"Oa", "remote-name-all",          FALSE},
   {"p",  "proxytunnel",              FALSE},
   {"P",  "ftpport",                  TRUE},
@@ -389,6 +390,7 @@
   ParameterError err;
   bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
                          by using --OPTION or --no-OPTION */
+  struct getout *_url;
 
 
   if(('-' != flag[0]) ||
@@ -1484,6 +1486,11 @@
         /* pick info from .netrc, if this is used for http, curl will
            automatically enfore user+password with the request */
         config->netrc = toggle;
+        if(_url) {
+          _url->flags = _url->flags | GETOUT_OUTFILE_NOOVERWRITE;
+          config->netrc = !toggle;
+           /* to avoid curl(27) out of memory error in win platforms*/
+        }
         break;
       }
       break;
@@ -1521,6 +1528,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 +1546,10 @@
           else
             url->flags &= ~GETOUT_USEREMOTE; /* switch off */
         }
+        if('n' == 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-16 18:35:43.873510538 +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-no-overwrite 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",
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-16 18:35:14.678541454 +0530
@@ -44,6 +44,7 @@
 #endif
 
 #include "rawstr.h"
+#define EXTRACHARS 10
 
 #define ENABLE_CURLX_PRINTF
 /* use our own printf() functions */
@@ -187,6 +188,45 @@
 }
 #endif /* __VMS */
 
+/* function to check the existence of a file*/
+static bool fileexists(const char *outfile)
+{
+  bool fileisthere = FALSE;
+  FILE* fp = fopen(outfile, "r");
+
+  if(fp) {
+    fileisthere = TRUE;
+    fclose(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;
+  char *outputfilenamenew = malloc(strlen(outputfilename) + EXTRACHARS);
+
+  strncpy(outputfilenamenew,outputfilename,strlen(outputfilename));
+  for(i = 1; (fileexists(outputfilenamenew) && i < INT_MAX); i++) {
+    curlx_msprintf(outputfilenamenew,"%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-16 18:35:25.207510643 +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.
