Solaris ネーミングの管理

バインディングの作成

次の例は、バインディングの作成方法を示しています。

#include <stdio.h> 
#include <xfn/xfn.h> 
#include <string.h> 
/*  
 このルーチンは "name" によって提供される名前を用いて
 バインディングを作成する。提供される名前のリファレンスのタイプは 
 "reference_type" で、アドレスのタイプは "address_type"である。
 関数の使用例として 
  fns_create_bindings(  	      
  "user/jsmith/service/calendar"、  	      
  "onc_calendar"、  	      
  "onc_cal_str"、  	      
  "jsmith&calserver");
 がある 
*/ 
int fns_create_bindings(  
 char *name,  
 char *reference_type,  
 char *address_type,  
 char *data) 
{ 	
 int return_status; 	
 FN_composite_name_t *binding_name; 	
 FN_identifier_t ref_id, addr_id; 	
 FN_status_t *status; 	
 FN_ref_t *reference; 	
 FN_ref_addr_t *address; 	
 FN_ctx_t *initial_context; 	
 /* 初期コンテキストの獲得 */ 	
 status = fn_status_create(); 	
 initial_context = fn_ctx_handle_from_initial(0, status); 	
 /* エラーメッセージの状態のチェック */ 	
 if ((return_status = fn_status_code(status)) != FN_SUCCESS) { 		
  fprintf(stderr, "Unable to obtain the initial context¥n"); 		
  return (return_status); 	
 } 	
 /* プリンタ名に付ける複合名の獲得 */ 	
 binding_name = fn_composite_name_from_str((unsigned char *) name); 	
 /* アドレスのコンストラクト */ 	
 addr_id.format = FN_ID_STRING; 	
 addr_id.length = strlen(address_type); 	
 addr_id.contents = (void *) address_type; 	
 address = fn_ref_addr_create(&addr_id, 		
  strlen(data), (const void *) data);  
 /* リファレンスのコンストラクト */ 	
 ref_id.format = FN_ID_STRING; 	
 ref_id.length = strlen(reference_type); 	
 ref_id.contents = (void *) reference_type; 	
 reference = fn_ref_create(&ref_id); 	
 /* リファレンスにアドレスを追加する */ 	
 fn_ref_append_addr(reference, address); 	 	
 /* 割り当ての作成 */ 	
 fn_ctx_bind(initial_context, binding_name, reference, 0, status); 	
 /* エラー状態をチェックして返す */ 	
 return_status = fn_status_code(status); 	
 fn_composite_name_destroy(binding_name); 	
 fn_ref_addr_destroy(address); 	
 fn_ref_destroy(reference); 	
 fn_ctx_destroy(initial_context); 	
 return (return_status); 
}