Main content
Programming Examples in C
The following list links to programming examples for the OpenVMS operating system. My intention is to do an example for nearly every LIB$
and SYS$
routine available.
Note that on the pages that show the examples, the navigation menu is not displayed to give me a little room to display the code. Use the browser back button to return to this page or click on the link at the bottom of each page to return to this list.
If you know nothing about LIB$
and SYS$
routines, you should probably start looking at these from the beginning. Else feel free to just dive in anywhere. Later programs will assume that you have read earlier ones.
Most of this code is not commented extensively (unlike my production code, which tends to be obsessively commented).
I do however try to give a brief description of a concept that is used extensively the first time it's used. One thing that deserves mention is error checking. I use a macro to do error checking, and have it included from a file, errchk.h. Don't forget to get this if you want to build any of the examples.
Most of the code builds with a simple
$ cc filename
$ link filename
If something special needs to be done, the code will have compile instructions included in comments. Also included in the comments will be warnings about privileges required and the possibility of shooting yourself in the foot by running the code. Read the license and disclaimer before running this code.
As an additional bonus, the code hyperlinks to the OpenVMS documentation for the particular system services or RTL routines called from the code.
I said at the start that I intend to do an example for nearly all routines. The routines that are left out usually fall into a fairly straightforward category that cause me to omit them. These categories are:
- Routines only appropriate to VAX. Sorry, I don't have a VAX any more to test these.
- Routines that differ only by their return method. If a routine has a synchronous and an asynchronous version (for example,
sys$getjpi
and sys$getjpiw
), I may only demonstrate one of them as the call arguments are exactly the same.
- Routines that differ only by having a version that supports 64 bit arguments. Most of these routines (for example,
sys$expreg
and sys$expreg_64
) differ only by accepting 64 bit addresses as arguments.
If you are searching for a routine that falls into one of these categories and you don't find it, and you desperately need an example, you can contact me and I'll see what I can do.
For you VAX users out there, a lot of the code is using an Alpha/IPF specific header that defines quadwords. The code will probably run with some minor modifications (such as defining quadword structures as a two longword array, and passing the address of the first array element to the function). If you find yourself totally stuck on a VAX, and the code does not have an #error directive in it indicating it's Alpha/IPF specific, you can contact me, and I'll attempt to un-stick you.
As usual, I would be very interested to hear comments or criticisms concerning this code.
Enjoy.
- lib$signal,
- lib$get_ef,
- lib$free_ef,
- lib$get_input,
- lib$put_output,
- sys$bintim,
- lib$add_times,
- lib$sub_times,
- lib$convert_date_string,
- lib$adawi,
- lib$analyze_sdesc,
- lib$analyze_sdesc_64,
- lib$callg,
- lib$bbssi,
- lib$bbcci,
- lib$char,
- lib$crc, lib$crc_table,
- lib$getdvi,
- lib$getjpi,
- lib$get_logical,
- lib$currency,
- lib$create_dir, sys$setddir,
- lib$sys_asctim,
- lib$cvtf_from_internal_time,
- lib$cvtf_to_internal_time,
- lib$cvt_vectim,
- sys$creprc,
- lib$cvt_dtb,
- lib$cvt_htb,
- lib$cvt_otb,
- lib$date_time,
- lib$day,
- lib$day_of_week,
- lib$delete_file,
- lib$digit_sep,
- lib$do_command,
- lib$wait,
- lib$spawn,
- lib$set_logical,
- lib$delete_logical,
- lib$set_symbol,
- lib$delete_symbol,
- lib$create_vm_zone, lib$get_vm, lib$show_vm, lib$show_vm_zone, lib$verify_vm_zone, lib$free_vm, lib$delete_vm_zone, lib$find_vm_zone, lib$stat_vm,
- lib$fid_to_name,
- lib$init_timer, lib$show_timer, lib$stat_timer, lib$free_timer,
- sys$putmsg,
- lib$establish, lib$revert,
- lib$find_file, lib$find_file_end,
- lib$addx,
- lib$getsyi,
- lib$get_command,
- lib$put_commmon, lib$get_common,
- lib$subx,
- lib$run_program,
- lib$sys_fao,
- lib$sys_faol,
- lib$sys_getmsg,
- lib$format_date_time, lib$get_maximum_date_length,
- lib$get_users_language,
- lib$ichar,
- lib$len,
- lib$index,
- lib$pause,
- lib$lp_lines,
- lib$polyg,
- lib$radix_point,
- lib$insqhi, lib$insqti, lib$remqhi, lib$remqti,
- sys$asctoid,
- lib$stop,
- lib$rename_file,
- lib$lookup_key,
- lib$locc,
- lib$matchc,
- lib$movc3,
- lib$movc5,
- lib$ediv,
- lib$insert_tree, lib$lookup_tree, lib$traverse_tree,
- lib$emul,
- lib$extv,
- lib$extzv,
- lib$ffc,
- sys$dclast,
- lib$ast_in_prog,
- sys$getjpiw,
- sys$getjpi, sys$clref, sys$setef, sys$waitfr,
- sys$assign, sys$dassgn,
- sys$getdvi, lib$reserve_ef, sys$wfland,
- sys$getdviw,
- sys$setprv,
- sys$setimr, sys$cantim, sys$hiber, sys$wake,
- sys$exit,
- sys$crembx,
- sys$delmbx,
- sys$ascefc, sys$dlcefc, sys$wflor, sys$readef, sys$dacefc,
- lib$getqui, lib$get_accnam, lib$format_sogw_prot,
- sys$gettim, sys$numtim,
- sys$setpri,
- sys$add_ident, sys$add_holder, sys$grantid, sys$revokid, sys$rem_holder, sys$rem_ident,
- sys$asctim,
- lib$get_foreign,
- lib$get_hostname, lib$expand_nodename, lib$get_fullname_offset, lib$sget1_dd, lib$sfree1_dd,
- sys$alloc, sys$dalloc,
- sys$device_scan,
- sys$erapat, sys$dismou, sys$mount, sys$qiow,
- sys$getsyi, sys$getsyiw, sys$synch,
- lib$enable_ctrl, lib$disable_ctrl,
- sys$create, sys$connect, sys$extend, sys$put, sys$flush, sys$get, sys$disconnect, sys$close, sys$erase,
- sys$purgws,
- sys$schdwk, sys$canwak,
- lib$file_scan, lib$file_scan_end,
- lib$sig_to_ret, lib$sig_to_stop,
- sys$add_proxy, sys$display_proxy, sys$verify_proxy, sys$delete_proxy,
- sys$crelnt, sys$crelnm, sys$dellnm,
- sys$getenv,
- sys$trnlnm,
- sys$dclexh, sys$canexh,
- sys$delprc,
- sys$cmkrnl,
- sys$getuai, sys$setuai,
- lib$find_image_symbol,
- sys$crmpsc, sys$updsec, sys$deltva,
- sys$adjwsl,
- sys$ascutc, sys$binutc, sys$numutc,
- sys$lkwset, sys$ulwset,
- lib$get_symbol,
- lib$get_vm_page, lib$free_vm_page,
- lib$asn_wth_mbx,
- sys$audit_eventw,
- sys$setup_avoid_preempt, sys$avoid_preempt,
- sys$sndopr,
- sys$brkthruw,
- sys$getutc,
- sys$resched,
- sys$setprn,
- sys$timcon,
- sys$icc_open_assoc, sys$icc_connectw, sys$icc_disconnectw, sys$icc_accept, sys$icc_receivew, sys$icc_transmitw, sys$icc_close_assoc,
- sys$setdfprot,
- sys$check_privilegew,
- sys$create_region_64, sys$cretva_64, sys$expreg_64, sys$setprt_64, sys$deltva_64, sys$delete_region_64,
- sys$start_transw, sys$end_transw, sys$abort_transw,
- sys$check_access,
- sys$find_held, sys$idtoasc, sys$find_holder, sys$finish_rdb,
- lib$insv,
- lib$mult_delta_time, lib$multf_delta_time,
- sys$lckpag, sys$ulkpag,
- sys$create_user_profile, sys$persona_create, sys$persona_modify, sys$persona_assume, sys$persona_clone, sys$persona_delete,
- sys$show_intrusion, sys$delete_intrusion,
- sys$getquiw, sys$sndjbcw,
- sys$setast,
- sys$hash_password,
- sys$acmw,
- sys$cmexec, sys$getlkiw,
- lib$tparse, lib$table_parse,
- sys$forcex,
- sys$fao, sys$faol,
- lib$tra_asc_ebc, lib$tra_ebc_asc,
- sys$start_align_fault_report, sys$get_align_fault_data, sys$stop_align_fault_report,
- sys$chkpro, sys$get_security,
- sys$setshlv,
- sys$setrwm,
- sys$set_process_propertiesw,
- sys$set_security, sys$parse_acl,
- sys$subsystem,
- sys$setcluevt, sys$tstcluevt, sys$clrcluevt,
- lib$scanc,
- lib$get_date_format,
- lib$emodg,
- lib$cvt_dx_dx,
- lib$scopy_dxdx,
- sys$process_scan,
- lib$skpc,
- lib$movtc,
- lib$scopy_r_dx,
- sys$create_bufobj, sys$delete_bufobj, sys$io_setup, sys$io_performw, sys$io_cleanup,
- sys$perm_report_align_fault, sys$perm_dis_align_fault_report,
- sys$crmpsc_gdzro_64, sys$mgblsc_64, sys$dgblsc,
- sys$setpra,
- sys$setswm,
- sys$io_fastpathw,
- sys$cpu_capabilities, sys$get_user_capability, sys$process_capabilities, sys$free_user_capability,
- sys$cancel,
- sys$check_fen,
- sys$cvt_filename,
- sys$dclcmh,
- sys$filescan,
- sys$format_audit,
- sys$get_region_info,
- sys$set_implicit_affinity,
- sys$suspnd, sys$resume,
- sys$unwind, lib$match_cond, sys$getmsg,
- sys$snderr,
- sys$clrast,
- sys$create_uid,
- sys$getrmi,
- sys$set_system_event, sys$clear_system_event,
- sys$acquire_galaxy_lock, sys$create_galaxy_lock, sys$create_galaxy_lock_table, sys$delete_galaxy_lock, sys$delete_galaxy_lock_table, sys$get_galaxy_lock_info, sys$get_galaxy_lock_size, sys$release_galaxy_lock,
- sys$create_gpfn, sys$mgblsc_gpfn_64,
- lib$lock_image, lib$unlock_image,
- lib$spanc,
- sys$wait, sys$read, sys$write, sys$enter, sys$remove,
- sys$init_vol,
- sys$rpcc_64,
- sys$enqw, sys$deq,
- lib$freen_dd,
- sys$device_path_scan,
- sys$purge_ws,
- lib$ffs,
- sys$proccess_affinity,
- lib$attach,
- sys$cpu_transitionw,
- sys$ieee_set_precision_mode, sys$ieee_set_rounding_mode, sys$ieee_set_fp_control,
- sys$get_arith_exception,
- sys$gettim_prec,
- sys$power_control,
- ots$cnvout,
- ots$cvt_t_x,
- ots$cvt_tb_l, ots$cvt_ti_l, ots$cvt_tl_l, ots$cvt_to_l, ots$cvt_tu_l, ots$cvt_tz_l,
- ots$cvt_l_tb, ots$cvt_l_ti, ots$cvt_l_tl, ots$cvt_l_to, ots$cvt_l_tu, ots$cvt_l_tz,
- ots$divc,
- ots$move3, ots$move5,
- ots$mulc,
- ots$powc,
- ots$powcj,
- ots$powjj,
- ots$scopy_dxdx, ots$sget1_dd, ots$sfree1_dd,
- ots$scopy_r_dx, ots$sfreen_dd,
- lib$get_curr_invo_context, lib$i64_get_curr_invo_context, lib$get_prev_invo_context, lib$i64_get_prev_invo_context, lib$i64_init_invo_context, lib$get_curr_invo_context, lib$get_prev_invo_context, lib$i64_prev_invo_end, tbk$alpha_symbolize, tbk$i64_symboli,
- sys$sigprc,
- sys$get_entropy