@@ -1411,34 +1411,39 @@ Addition. This operator also performs string and list concatenation.
14111411 }
14121412
14131413 error builtin_infile (const vector<atom>& vargs, atom* result) {
1414- string mode = " rb" ;
1414+ const char * mode = " rb" ;
14151415 if (vargs.size () == 2 ) {
14161416 if (vargs[1 ].type != T_SYM ) return ERROR_TYPE ;
14171417 if (*get<sym>(vargs[1 ].val ) == " text" ) {
14181418 mode = " r" ;
14191419 }
14201420 }
14211421 else if (vargs.size () == 1 ) {
1422- /* pass */
14231422 }
14241423 else return ERROR_ARGS ;
14251424 atom a = vargs[0 ];
14261425 if (a.type != T_STRING ) return ERROR_TYPE ;
1427- FILE * fp = fopen (a.asp <string>().c_str (), mode. c_str () );
1426+ FILE * fp = fopen (a.asp <string>().c_str (), mode);
14281427 if (!fp) return ERROR_FILE ;
14291428 *result = make_input (fp);
14301429 return ERROR_OK ;
14311430 }
14321431
1432+ /* outfile filename ['append]
1433+ Opens the specified path for writing. By default, the file is truncated if it already exists. Returns an output - port. Arc supports only 'text mode for outfile. */
14331434 error builtin_outfile (const vector<atom>& vargs, atom* result) {
1434- if (vargs.size () == 1 ) {
1435- atom a = vargs[0 ];
1436- if (a.type != T_STRING ) return ERROR_TYPE ;
1437- FILE * fp = fopen (a.asp <string>().c_str (), " w" );
1438- *result = make_output (fp);
1439- return ERROR_OK ;
1435+ const char * mode = " w" ;
1436+ if (vargs.size () == 2 ) {
1437+ mode = " a" ;
1438+ }
1439+ else if (vargs.size () == 1 ) {
14401440 }
14411441 else return ERROR_ARGS ;
1442+ atom a = vargs[0 ];
1443+ if (a.type != T_STRING ) return ERROR_TYPE ;
1444+ FILE * fp = fopen (a.asp <string>().c_str (), mode);
1445+ *result = make_output (fp);
1446+ return ERROR_OK ;
14421447 }
14431448
14441449 /* close port ... */
0 commit comments