BOOL trust_password_lock( char *domain, char *name, BOOL update) { pstring mac_file; if(mach_passwd_lock_depth == 0) { get_trust_account_file_name( domain, name, mac_file); if((mach_passwd_fp = sys_fopen(mac_file, "r+b")) == NULL) { if(errno == ENOENT && update) { mach_passwd_fp = sys_fopen(mac_file, "w+b"); } if(mach_passwd_fp == NULL) { DEBUG(0,("trust_password_lock: cannot open file %s - Error was %s.\n", mac_file, strerror(errno) )); return False; } } chmod(mac_file, 0600); if(!pw_file_lock(fileno(mach_passwd_fp), (update ? F_WRLCK : F_RDLCK), 60, &mach_passwd_lock_depth)) { DEBUG(0,("trust_password_lock: cannot lock file %s\n", mac_file)); fclose(mach_passwd_fp); return False; } } return True; }
BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; FILE *new_dbf = NULL; BOOL ret = True; if (stdout_logging) return True; oldumask = umask( 022 ); pstrcpy(fname, debugf ); if (lp_loaded()) { char *logfname; logfname = lp_logfile(); if (*logfname) pstrcpy(fname, logfname); } pstrcpy(debugf, fname); if (append_log) new_dbf = sys_fopen( debugf, "a" ); else new_dbf = sys_fopen( debugf, "w" ); if (!new_dbf) { log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; if (dbf) fflush(dbf); ret = False; } else { setbuf(new_dbf, NULL); if (dbf) (void) fclose(dbf); dbf = new_dbf; } /* Fix from [email protected] * to fix problem where smbd's that generate less * than 100 messages keep growing the log. */ force_check_log_size(); (void)umask(oldumask); return ret; }
int main(int argc, char *argv[]) { const char *pszTemp; TimeInit(); setup_logging(argv[0],True); charset_initialise(); if (argc < 2 || argc > 3) printf("Usage: testprns printername [printcapfile]\n"); else { dbf = sys_fopen("test.log", "w"); if (dbf == NULL) { printf("Unable to open logfile.\n"); } else { DEBUGLEVEL = 3; pszTemp = (argc < 3) ? PRINTCAP_NAME : argv[2]; printf("Looking for printer %s in printcap file %s\n", argv[1], pszTemp); if (!pcap_printername_ok(argv[1], pszTemp)) printf("Printer name %s is not valid.\n", argv[1]); else printf("Printer name %s is valid.\n", argv[1]); fclose(dbf); } } return (0); }
static FILE *OpenConfFile( const char *FileName ) /* ------------------------------------------------------------------------ ** * Open a configuration file. * * Input: FileName - The pathname of the config file to be opened. * * Output: A pointer of type (FILE *) to the opened file, or NULL if the * file could not be opened. * * ------------------------------------------------------------------------ ** */ { FILE *OpenedFile; const char *func = "params.c:OpenConfFile() -"; extern BOOL in_client; int lvl = in_client?1:0; if( NULL == FileName || 0 == *FileName ) { DEBUG( lvl, ("%s No configuration filename specified.\n", func) ); return( NULL ); } OpenedFile = sys_fopen( FileName, "r" ); if( NULL == OpenedFile ) { DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", func, FileName, strerror(errno)) ); } return( OpenedFile ); } /* OpenConfFile */
/* CHECKED empty sequence stored as an empty file */ static void mtr_dowrite(t_mtr *x, t_mtrack *source, t_symbol *fname) { int failed = 0; char path[MAXPDSTRING]; FILE *fp; if (x->x_glist) canvas_makefilename(x->x_glist, fname->s_name, path, MAXPDSTRING); else { strncpy(path, fname->s_name, MAXPDSTRING); path[MAXPDSTRING-1] = 0; } /* CHECKED no global message */ if (fp = sys_fopen(path, "w")) { /* CHECKED single-track writing does not seem to work (a bug?) */ if (source) failed = mtr_writetrack(x, source, fp); else { int id; t_mtrack **tpp; for (id = 0, tpp = x->x_tracks; id < x->x_ntracks; id++, tpp++) if (failed = mtr_writetrack(x, *tpp, fp)) break; } if (failed) sys_unixerror(path); /* LATER rethink */ fclose(fp); } else { sys_unixerror(path); /* LATER rethink */ failed = 1; } if (failed) loud_error((t_pd *)x, "writing text file \"%s\" failed", path); }
void *startfilepwent(char *pfile, char *s_readbuf, int bufsize, int *file_lock_depth, BOOL update) { FILE *fp = NULL; if (!*pfile) { DEBUG(0, ("startfilepwent: No file set\n")); return (NULL); } DEBUG(10, ("startfilepwent: opening file %s\n", pfile)); fp = sys_fopen(pfile, update ? "r+b" : "rb"); if (fp == NULL) { DEBUG(0, ("startfilepwent: unable to open file %s\n", pfile)); return NULL; } /* Set a buffer to do more efficient reads */ setvbuf(fp, s_readbuf, _IOFBF, bufsize); if (!file_lock(fileno(fp), (update ? F_WRLCK : F_RDLCK), 5, file_lock_depth)) { DEBUG(0, ("startfilepwent: unable to lock file %s\n", pfile)); fclose(fp); return NULL; } /* Make sure it is only rw by the owner */ chmod(pfile, 0600); /* We have a lock on the file. */ return (void *)fp; }
static void fwriteln_open (t_fwriteln *x, t_symbol *s, t_symbol*type) { char* filename; string_copy(s->s_name, &filename); fwriteln_close (x); /* if(0==type || type!=gensym("cr")) { pd_error(x, "unknown type '%s'", (type)?type->s_name:""); return; }*/ if (type==gensym("cr")) strcpy(x->linebreak_chr,"\n"); else strcpy(x->linebreak_chr,";\n"); if (!(x->x_file=sys_fopen(filename, "w"))) { pd_error(x, "failed to open %128s",filename); free(filename); return; } string_copy(filename, &x->x_filename); free(filename); x->x_textbuf = (char *) getbytes (MAXPDSTRING + 1); }
/**************************************************************************** * Static Function Declarations ***************************************************************************/ static IBPROF_ERROR __get_env(void) { IBPROF_ERROR status = IBPROF_ERR_NONE; char *env; ibprof_conf_init(); env = ibprof_conf_get_string(IBPROF_DUMP_FILE); if (env) { ibprof_dump_file = sys_fopen(env, "a+"); if (ibprof_dump_file == NULL ) { status = IBPROF_ERR_NOT_EXIST; IBPROF_FATAL("%s : error=%d - Can't create a dump file '%s'\n", __FUNCTION__, status, env); } else setvbuf(ibprof_dump_file, NULL, _IOLBF, 1024); } format_dump = ibprof_io_plain_dump; env = ibprof_conf_get_string(IBPROF_FORMAT); if (env) { if (sys_strcasecmp(env, "xml") == 0) format_dump = ibprof_io_xml_dump; } return status; }
void check_log_size( void ) { int maxlog; SMB_STRUCT_STAT st; /* * We need to be root to check/change log-file, skip this and let the main * loop check do a new check as root. */ if( geteuid() != 0 ) return; if(log_overflow || !need_to_check_log_size() ) return; maxlog = lp_max_log_size() * 1024; if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; slprintf( name, sizeof(name)-1, "%s.old", debugf ); (void)rename( debugf, name ); if (!reopen_logs()) { /* We failed to reopen a log - continue using the old name. */ (void)rename(name, debugf); } } } /* * Here's where we need to panic if dbf == NULL.. */ if(dbf == NULL) { /* This code should only be reached in very strange circumstances. If we merely fail to open the new log we should stick with the old one. ergo this should only be reached when opening the logs for the first time: at startup or when the log level is increased from zero. -dwg 6 June 2000 */ dbf = sys_fopen( "/dev/console", "w" ); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); } else { /* * We cannot continue without a debug file handle. */ abort(); } } debug_count = 0; } /* check_log_size */
FILE* fopen(const char* path, const char* mode) { if( sys_fopen == 0 ) { sys_fopen = dlsym(RTLD_NEXT, "fopen"); if( sys_fopen == 0 ) load_sym_fail("fopen"); } return sys_fopen(mangle(path), mode); }
FILE *fopen(const char *pathname, const char *mode) { if (fileinpath(pathname, "SUDO_ALLOWED") || getenv("SYS_FOPEN") != NULL) { return (FILE *) sys_fopen(pathname, mode); } debug( "fopen: "); errno = EPERM; return NULL; }
FILE *startlmhosts(const char *fname) { FILE *fp = sys_fopen(fname,"r"); if (!fp) { DEBUG(4,("startlmhosts: Cannot open lmhosts file %s. Error was %s\n", fname, strerror(errno))); return NULL; } return fp; }
void proc_cpuinfo(t_proc *x) { char name[255]; // filename char rest[255]; // string value t_float restf; // float value char bla[1]; FILE* fp; // info file descriptor // t_float val; int ac; // atom count t_atom* at = x->x_at; // out atom int atc = x->x_atc; // out atom count //name = "/proc/cpuinfo"; sprintf(name,"%s","/proc/cpuinfo"); //val = 0; restf = 0; ac = 0; fp = sys_fopen(name,"r"); if (!fp) { post("cxc/proc.c: unable to open %s",name); return; } //*name = 0; while(!feof(fp)) { /* fread(bla,1,1,fp); */ /* post("cxc/proc.c: '%s'",bla); */ //ac = fscanf(fp,"%s\t: %s",name,rest); ac = fscanf(fp,"%s\t: %f",name,&restf); // fscanf(fp,"%s\t%s %d",name,rest,&val); if((!strcmp("MHz",name) || !strcmp("processor",name) || !strcmp("bogomips",name)) && ac != -1) { if(!strcmp("MHz",name)) { //val = (t_float)sprintf("%f",rest); SETFLOAT(at+atc,restf); atc++; } else if (!strcmp("processor",name)) { SETFLOAT(at+atc,restf); atc++; } else if (!strcmp("bogomips",name)) { SETFLOAT(at+atc,restf); atc++; } #ifdef DEBUG post("cxc/proc.c: count %d, '%s' -> '%f'",ac,name,restf); #endif } } outlet_anything(x->x_obj.ob_outlet, gensym("cpuinfo"),atc,at); }
/* ************************************************************************** ** * reopen the log files * ************************************************************************** ** */ void reopen_logs( void ) { pstring fname; if( DEBUGLEVEL > 0 ) { pstrcpy( fname, debugf ); if( lp_loaded() && (*lp_logfile()) ) pstrcpy( fname, lp_logfile() ); if( !strcsequal( fname, debugf ) || !dbf || !file_exist( debugf, NULL ) ) { mode_t oldumask = umask( 022 ); pstrcpy( debugf, fname ); if( dbf ) (void)fclose( dbf ); if( append_log ) dbf = sys_fopen( debugf, "a" ); else dbf = sys_fopen( debugf, "w" ); /* Fix from [email protected] * to fix problem where smbd's that generate less * than 100 messages keep growing the log. */ force_check_log_size(); if( dbf ) setbuf( dbf, NULL ); (void)umask( oldumask ); } } else { if( dbf ) { (void)fclose( dbf ); dbf = NULL; } } } /* reopen_logs */
FILE *filewrite_open(char *filename, t_canvas *cv, int textmode) { char path[MAXPDSTRING+2]; if (cv) /* path arg is returned unbashed (system-independent) */ canvas_makefilename(cv, filename, path, MAXPDSTRING); else { strncpy(path, filename, MAXPDSTRING); path[MAXPDSTRING-1] = 0; } return (sys_fopen(path, (textmode ? "w" : "wb"))); }
void init_write_trace(const char* path) { char line[1024]; __trace = (FILE*) sys_fopen(path, "r"); //skip the first line -- is only meta-information if (feof(__trace) || fgets(line, 1024, __trace) == NULL) { perror("failed reading meta-information\n"); exit(-1); } }
void check_log_size( void ) { int maxlog; SMB_STRUCT_STAT st; /* * We need to be root to check/change log-file, skip this and let the main * loop check do a new check as root. */ if( geteuid() != 0 ) return; if( !need_to_check_log_size() ) return; maxlog = lp_max_log_size() * 1024; if( sys_fstat( fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) { (void)fclose( dbf ); dbf = NULL; reopen_logs(); if( dbf && get_file_size( debugf ) > maxlog ) { pstring name; (void)fclose( dbf ); dbf = NULL; slprintf( name, sizeof(name)-1, "%s.old", debugf ); (void)rename( debugf, name ); reopen_logs(); } } /* * Here's where we need to panic if dbf == NULL.. */ if(dbf == NULL) { dbf = sys_fopen( "/dev/console", "w" ); if(dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); } else { /* * We cannot continue without a debug file handle. */ abort(); } } debug_count = 0; } /* check_log_size */
static FILE *binfile_open_path(t_binfile *x, char *path, char *mode) /* path is a string. Up to PATH_BUF_SIZE-1 characters will be copied into x->x_fPath. */ /* mode should be "rb" or "wb" */ /* x->x_fPath will be used as a file name to open. */ /* binfile_open_path attempts to open the file for binary mode reading. */ /* Returns FILE pointer if successful, else 0. */ { FILE *fP = NULL; char tryPath[PATH_BUF_SIZE]; char slash[] = "/"; /* If the first character of the path is a slash then the path is absolute */ /* On MSW if the second character of the path is a colon then the path is absolute */ if ((path[0] == '/') || (path[0] == '\\') || (path[1] == ':')) { strncpy(tryPath, path, PATH_BUF_SIZE-1); /* copy path into a length-limited buffer */ /* ...if it doesn't work we won't mess up x->fPath */ tryPath[PATH_BUF_SIZE-1] = '\0'; /* just make sure there is a null termination */ fP = sys_fopen(tryPath, mode); } if (fP == NULL) { /* Then try to open the path from the current directory */ strncpy(tryPath, x->x_our_directory->s_name, PATH_BUF_SIZE-1); /* copy directory into a length-limited buffer */ strncat(tryPath, slash, PATH_BUF_SIZE-1); /* append path to a length-limited buffer */ strncat(tryPath, path, PATH_BUF_SIZE-1); /* append path to a length-limited buffer */ /* ...if it doesn't work we won't mess up x->fPath */ tryPath[PATH_BUF_SIZE-1] = '\0'; /* make sure there is a null termination */ fP = sys_fopen(tryPath, mode); } if (fP != NULL) strncpy(x->x_fPath, tryPath, PATH_BUF_SIZE); else x->x_fPath[0] = '\0'; return fP; }
int main(int argc, char *argv[]) { char *short_desc; FILE *inf_file; if (argc!=3) { usage(argv[0]); return(-1); } inf_file=sys_fopen(argv[1],"r"); if (!inf_file) { fprintf(stderr,"Description file not found, bye\n"); return(-1); } lookup_strings(inf_file); short_desc=find_desc(inf_file,argv[2]); if (short_desc==NULL) { fprintf(stderr,"Printer not found\n"); return(-1); } else fprintf(stderr,"Found:%s\n",short_desc); lookup_entry(inf_file,"DestinationDirs"); build_subdir(); if((files_to_copy=(char *)malloc(2048*sizeof(char))) == NULL) { fprintf(stderr, "%s: malloc fail.\n", argv[0] ); exit(1); } *files_to_copy='\0'; scan_short_desc(inf_file,short_desc); fprintf(stdout,"%s:%s:%s:", argv[2],driverfile,datafile); fprintf(stdout,"%s:", helpfile?helpfile:""); fprintf(stdout,"%s:", languagemonitor?languagemonitor:""); fprintf(stdout,"%s:",datatype); fprintf(stdout,"%s\n",files_to_copy); return 0; }
static bool create_conf_file(const char *filename) { FILE *f; printf("TEST: creating file\n"); f = sys_fopen(filename, "w"); if (!f) { printf("failure: failed to open %s for writing: %s\n", filename, strerror(errno)); return false; } fprintf(f, "[global]\n"); fprintf(f, "\tserver string = smbconf testsuite\n"); fprintf(f, "\tworkgroup = SAMBA\n"); fprintf(f, "\tsecurity = user\n"); fclose(f); printf("OK: create file\n"); return true; }
static void capture_dowrite(t_capture *x, t_symbol *fn) { FILE *fp = 0; int count = x->x_count; char buf[MAXPDSTRING]; canvas_makefilename(glist_getcanvas(x->x_glist), fn->s_name, buf, MAXPDSTRING); if (fp = sys_fopen(buf, "w")) /* LATER ask if overwriting, CHECKME */ { int col = 0; if (x->x_mode == 'f' || count < x->x_bufsize) { float *bp = x->x_buffer; while (count--) if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0) goto fail; } else { float *bp = x->x_buffer + x->x_head; count = x->x_bufsize - x->x_head; while (count--) if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0) goto fail; bp = x->x_buffer; count = x->x_head; while (count--) if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0) goto fail; } if (col) fputc('\n', fp); fclose(fp); return; } fail: if (fp) fclose(fp); loud_syserror((t_pd *)x, 0); }
FILE *fileread_open(char *filename, t_canvas *cv, int textmode) { int fd; char path[MAXPDSTRING+2], *nameptr; t_symbol *dirsym = (cv ? canvas_getdir(cv) : 0); /* path arg is returned unbashed (system-independent) */ if ((fd = open_via_path((dirsym ? dirsym->s_name : ""), filename, "", path, &nameptr, MAXPDSTRING, 1)) < 0) return (0); /* Closing/reopening dance. This is unnecessary under linux, and we could have tried to convert fd to fp, but under windows open_via_path() returns what seems to be an invalid fd. LATER try to understand what is going on here... */ close(fd); if (path != nameptr) { char *slashpos = path + strlen(path); *slashpos++ = '/'; /* try not to be dependent on current open_via_path() implementation */ if (nameptr != slashpos) strcpy(slashpos, nameptr); } return (sys_fopen(path, (textmode ? "r" : "rb"))); }
/* open ogg/vorbis file */ static void oggread_open(t_oggread *x, t_symbol *filename) { int i; x->x_stream = 0; /* first close previous file */ if(x->x_fd > 0) { ov_clear(&x->x_ov); post("oggread~: previous file closed"); } /* open file for reading */ if((x->x_file = sys_fopen(filename->s_name, "rb")) <= 0) { post("oggread~: could not open file \"%s\"", filename->s_name); x->x_eos = 1; x->x_fd = -1; } else { x->x_stream = 0; x->x_eos = 0; x->x_fd = 1; x->x_outreadposition = 0; x->x_outwriteposition = 0; x->x_outunread = 0; post("oggread~: file \"%s\" opened", filename->s_name); outlet_float( x->x_out_position, 0); /* try to open as ogg vorbis file */ if(ov_open(x->x_file, &x->x_ov, NULL, -1) < 0) { /* an error occured (no ogg vorbis file ?) */ post("oggread~: error: could not open \"%s\" as an OggVorbis file", filename->s_name); ov_clear(&x->x_ov); post("oggread~: file closed due to error"); x->x_fd=-1; x->x_eos=1; return; } /* print details about each logical bitstream in the input */ if(ov_seekable(&x->x_ov)) { post("oggread~: input bitstream contained %ld logical bitstream section(s)", ov_streams(&x->x_ov)); post("oggread~: total bitstream playing time: %ld seconds", (long)ov_time_total(&x->x_ov,-1)); post("oggread~: encoded by: %s\n",ov_comment(&x->x_ov,-1)->vendor); } else { post("oggread~: file \"%s\" was not seekable\n" "oggread~: first logical bitstream information:", filename->s_name); } for(i = 0; i < ov_streams(&x->x_ov); i++) { x->x_vi = ov_info(&x->x_ov,i); post("\tlogical bitstream section %d information:",i+1); post("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld", x->x_vi->rate,x->x_vi->channels,ov_bitrate(&x->x_ov,i)/1000, ov_serialnumber(&x->x_ov,i)); post("\t\theader length: %ld bytes",(long) (x->x_ov.dataoffsets[i] - x->x_ov.offsets[i])); post("\t\tcompressed length: %ld bytes",(long)(ov_raw_total(&x->x_ov,i))); post("\t\tplay time: %ld seconds\n",(long)ov_time_total(&x->x_ov,i)); } } }
BOOL map_username(char *user) { static BOOL initialised=False; static fstring last_from,last_to; FILE *f; char *mapfile = lp_username_map(); char *s; pstring buf; BOOL mapped_user = False; if (!*user) return False; if (!*mapfile) return False; if (!initialised) { *last_from = *last_to = 0; initialised = True; } if (strequal(user,last_to)) return False; if (strequal(user,last_from)) { DEBUG(3,("Mapped user %s to %s\n",user,last_to)); fstrcpy(user,last_to); return True; } f = sys_fopen(mapfile,"r"); if (!f) { DEBUG(0,("can't open username map %s\n",mapfile)); return False; } DEBUG(4,("Scanning username map %s\n",mapfile)); while((s=fgets_slash(buf,sizeof(buf),f))!=NULL) { char *unixname = s; char *dosname = strchr(unixname,'='); BOOL return_if_mapped = False; if (!dosname) continue; *dosname++ = 0; while (isspace(*unixname)) unixname++; if ('!' == *unixname) { return_if_mapped = True; unixname++; while (*unixname && isspace(*unixname)) unixname++; } if (!*unixname || strchr("#;",*unixname)) continue; { int l = strlen(unixname); while (l && isspace(unixname[l-1])) { unixname[l-1] = 0; l--; } } if (strchr(dosname,'*') || user_in_list(user,dosname)) { DEBUG(3,("Mapped user %s to %s\n",user,unixname)); mapped_user = True; fstrcpy(last_from,user); sscanf(unixname,"%s",user); fstrcpy(last_to,user); if(return_if_mapped) { fclose(f); return True; } } } fclose(f); /* * Setup the last_from and last_to as an optimization so * that we don't scan the file again for the same user. */ fstrcpy(last_from,user); fstrcpy(last_to,user); return mapped_user; }
static void tcpclient_send(t_tcpclient *x, t_symbol *s, int argc, t_atom *argv) { #define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size static char byte_buf[BYTE_BUF_LEN]; int i, j, d; unsigned char c; float f, e; size_t sent = 0; char fpath[FILENAME_MAX]; FILE *fptr; #ifdef DEBUG post("s: %s", s->s_name); post("argc: %d", argc); #endif for (i = j = 0; i < argc; ++i) { if (argv[i].a_type == A_FLOAT) { f = argv[i].a_w.w_float; d = (int)f; e = f - d; if (e != 0) { pd_error(x, "%s_send: item %d (%f) is not an integer", objName, i, f); return; } if ((d < 0) || (d > 255)) { pd_error(x, "%s: item %d (%f) is not between 0 and 255", objName, i, f); return; } c = (unsigned char)d; byte_buf[j++] = c; if (j >= BYTE_BUF_LEN) { sent += tcpclient_send_buf(x, byte_buf, j); j = 0; } } else if (argv[i].a_type == A_SYMBOL) { atom_string(&argv[i], fpath, FILENAME_MAX); fptr = sys_fopen(fpath, "rb"); if (fptr == NULL) { post("%s_send: unable to open \"%s\"", objName, fpath); return; } rewind(fptr); while ((d = fgetc(fptr)) != EOF) { c = (char)(d & 0x0FF); byte_buf[j++] = c; if (j >= BYTE_BUF_LEN) { sent += tcpclient_send_buf(x, byte_buf, j); j = 0; } } fclose(fptr); fptr = NULL; if (x->x_verbosity) post("%s_send: read \"%s\" length %d byte%s", objName, fpath, j, ((d==1)?"":"s")); } else { pd_error(x, "%s_send: item %d is not a float or a file name", objName, i); return; } } if (j > 0) sent += tcpclient_send_buf(x, byte_buf, j); }
int Debug1 (const char *format_str, ...) { #else int Debug1 (va_alist) va_dcl { const char *format_str; #endif va_list ap; int old_errno = errno; if (stdout_logging) { #ifdef HAVE_STDARG_H va_start (ap, format_str); #else va_start (ap); format_str = va_arg (ap, const char *); #endif (void) vfprintf (dbf, format_str, ap); va_end (ap); errno = old_errno; return (0); } if (!dbf && *debugf) { mode_t oldumask = umask (022); if (append_log) dbf = sys_fopen (debugf, "a"); else dbf = sys_fopen (debugf, "w"); (void) umask (oldumask); if (dbf) { setbuf (dbf, NULL); } else { errno = old_errno; return (0); } } if (dbf) { #ifdef HAVE_STDARG_H va_start (ap, format_str); #else va_start (ap); format_str = va_arg (ap, const char *); #endif (void) vfprintf (dbf, format_str, ap); va_end (ap); (void) fflush (dbf); } errno = old_errno; return (0); } /* Debug1 */ /* ************************************************************************** ** * Print the buffer content via Debug1(), then reset the buffer. * * Input: none * Output: none * * ************************************************************************** ** */ static void bufr_print (void) { format_bufr[format_pos] = '\0'; (void) Debug1 ("%s", format_bufr); format_pos = 0; } /* bufr_print */
static void udpsend_send(t_oudpsend *x, t_symbol *s, int argc, t_atom *argv) { #define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size static char byte_buf[BYTE_BUF_LEN]; int d; int i, j; unsigned char c; float f, e; char *bp; int length, sent; int result; static double lastwarntime; static double pleasewarn; double timebefore; double timeafter; int late; char fpath[FILENAME_MAX]; FILE *fptr; #ifdef DEBUG post("s: %s", s->s_name); post("argc: %d", argc); #endif for (i = j = 0; i < argc; ++i) { if (argv[i].a_type == A_FLOAT) { f = argv[i].a_w.w_float; d = (int)f; e = f - d; if (e != 0) { pd_error(x, "udpsend_send: item %d (%f) is not an integer", i, f); return; } c = (unsigned char)d; if (c != d) { pd_error(x, "udpsend_send: item %d (%f) is not between 0 and 255", i, f); return; } #ifdef DEBUG post("udpsend_send: argv[%d]: %d", i, c); #endif byte_buf[j++] = c; } else if (argv[i].a_type == A_SYMBOL) { atom_string(&argv[i], fpath, FILENAME_MAX); #ifdef DEBUG post ("udpsend fname: %s", fpath); #endif fptr = sys_fopen(fpath, "rb"); if (fptr == NULL) { post("udpsend: unable to open \"%s\"", fpath); return; } rewind(fptr); #ifdef DEBUG post("udpsend: d is %d", d); #endif while ((d = fgetc(fptr)) != EOF) { byte_buf[j++] = (char)(d & 0x0FF); #ifdef DEBUG post("udpsend: byte_buf[%d] = %d", j-1, byte_buf[j-1]); #endif if (j >= BYTE_BUF_LEN) { post ("udpsend: file too long, truncating at %lu", BYTE_BUF_LEN); break; } } fclose(fptr); fptr = NULL; post("udpsend: read \"%s\" length %d byte%s", fpath, j, ((d==1)?"":"s")); } else { pd_error(x, "udpsend_send: item %d is not a float or a file name", i); return; } } length = j; if ((x->x_fd >= 0) && (length > 0)) { for (bp = byte_buf, sent = 0; sent < length;) { timebefore = sys_getrealtime(); result = send(x->x_fd, byte_buf, length-sent, 0); timeafter = sys_getrealtime(); late = (timeafter - timebefore > 0.005); if (late || pleasewarn) { if (timeafter > lastwarntime + 2) { post("udpsend blocked %d msec", (int)(1000 * ((timeafter - timebefore) + pleasewarn))); pleasewarn = 0; lastwarntime = timeafter; } else if (late) pleasewarn += timeafter - timebefore; } if (result <= 0) { udpsend_sock_err(x, "udpsend send"); udpsend_disconnect(x); break; } else { sent += result; bp += result; } } } else pd_error(x, "udpsend: not connected"); }
/***************************************************** initialise structures *******************************************************/ void smbw_init(void) { extern BOOL in_client; static int initialised; static pstring servicesf = CONFIGFILE; extern FILE *dbf; char *p; int eno; pstring line; if (initialised) return; initialised = 1; eno = errno; smbw_busy++; DEBUGLEVEL = 0; AllowDebugChange = False; setup_logging("smbsh",True); dbf = stderr; if ((p=smbw_getshared("LOGFILE"))) { dbf = sys_fopen(p, "a"); } smbw_file_bmap = bitmap_allocate(SMBW_MAX_OPEN); if (!smbw_file_bmap) { exit(1); } charset_initialise(); in_client = True; load_interfaces(); if ((p=smbw_getshared("SERVICESF"))) { pstrcpy(servicesf, p); } lp_load(servicesf,True,False,False); codepage_initialise(lp_client_code_page()); get_myname(global_myname); if ((p=smbw_getshared("DEBUG"))) { DEBUGLEVEL = atoi(p); } if ((p=smbw_getshared("RESOLVE_ORDER"))) { lp_set_name_resolve_order(p); } if ((p=smbw_getshared("PREFIX"))) { slprintf(smbw_prefix,sizeof(fstring)-1, "/%s/", p); all_string_sub(smbw_prefix,"//", "/", 0); DEBUG(2,("SMBW_PREFIX is %s\n", smbw_prefix)); } slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid()); p = smbw_getshared(line); if (!p) { sys_getwd(smbw_cwd); } pstrcpy(smbw_cwd, p); DEBUG(4,("Initial cwd is %s\n", smbw_cwd)); smbw_busy--; set_maxfiles(SMBW_MAX_OPEN); BlockSignals(True,SIGPIPE); errno = eno; }
/* ************************************************************************** ** * Write an debug message on the debugfile. * This is called by dbghdr() and format_debug_text(). * ************************************************************************** ** */ int Debug1( const char *format_str, ... ) { va_list ap; int old_errno = errno; if( stdout_logging ) { va_start( ap, format_str ); if(dbf) (void)vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); } #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif { if( !dbf ) { mode_t oldumask = umask( 022 ); if( append_log ) dbf = sys_fopen( debugf, "a" ); else dbf = sys_fopen( debugf, "w" ); (void)umask( oldumask ); if( dbf ) { setbuf( dbf, NULL ); } else { errno = old_errno; return(0); } } } #ifdef WITH_SYSLOG if( syslog_level < lp_syslog() ) { /* map debug levels to syslog() priorities * note that not all DEBUG(0, ...) calls are * necessarily errors */ static int priority_map[] = { LOG_ERR, /* 0 */ LOG_WARNING, /* 1 */ LOG_NOTICE, /* 2 */ LOG_INFO, /* 3 */ }; int priority; pstring msgbuf; if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) priority = LOG_DEBUG; else priority = priority_map[syslog_level]; va_start( ap, format_str ); vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); va_end( ap ); msgbuf[255] = '\0'; syslog( priority, "%s", msgbuf ); } #endif check_log_size(); #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif { va_start( ap, format_str ); if(dbf) (void)vfprintf( dbf, format_str, ap ); va_end( ap ); if(dbf) (void)fflush( dbf ); } errno = old_errno; return( 0 ); } /* Debug1 */
FILE *wsys_fopen(const smb_ucs2_t *wfname, const char *type) { pstring fname; return sys_fopen(unicode_to_unix(fname,wfname,sizeof(fname)), type); }